Skip to content

mritunjayr/java-practice-exercise-3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Language Basics - Practice Exercise 3


  1. Create a class called StudentMarks, which prompts user for the number of students, reads it from the keyboard, and saves it in an int variable called numOfStudents. It then prompts user for the grades of each of the students and saves them in an int array called stuGrades. Your program shall check that the grade is between 0 and 100 else has to trow an error message.

  2. Write a program to compute the addition of two matrix, Read the number of rows and columns as input, also the values of each matrix Output: Input number of rows of matrix: 3

     Input number of columns of matrix: 2
    
     Input elements of first matrix: 1 2 3 4 5 6
    
     Input the elements of second matrix: 9 8 7 6 5 4
    
     Sum of the matrices:-
    
     10 10
    
     10 10
    
     10 10
    
  3. Write a java program to calculate first and last date of a week. Output:

     First Date of Week: Mon 24/07/2017
     Last date of the week: Sun 30/07/2017
    
  4. Write a program to set up an array of places, Loop round and remove the vowels. Display the new words in console

    Input:

     India
     United States
     Germany
     Egypt
     czechoslovakia
    

    Output:

     Place Name without Vowels:0 Ind
     Place Name without Vowels:1 Untd Stts
    
     Place Name without Vowels:2 Grmny
     Place Name without Vowels:3 Egypt
     Place Name without Vowels:4 czchslvk
    
  5. Write a program to create a ChessBoard pattern with the help of multidimensional array, where WWrepresents white color and BB represents Black color. Output:

     My Chess Board
     WW|BB|WW|BB|WW|BB|WW|BB|
     BB|WW|BB|WW|BB|WW|BB|WW|
     WW|BB|WW|BB|WW|BB|WW|BB|
     BB|WW|BB|WW|BB|WW|BB|WW|
     WW|BB|WW|BB|WW|BB|WW|BB|
     BB|WW|BB|WW|BB|WW|BB|WW|
     WW|BB|WW|BB|WW|BB|WW|BB|
     BB|WW|BB|WW|BB|WW|BB|WW|
    
  6. Write a program to find out if a series of 7 digits are consecutive numbers. To make this easier, assume the digits are a string and use split()

     Input: 98,96,95,94,93
     Output: 98,96,95,94,93 non consecutive numbers
     Input: 54,53,52,51,50,49,48
     Output : 54,53,52,51,50,49,48 are consecutive numbers
     Input: 1,2,3,4,5,6,6
     Output: 1,2,3,4,5,6,6 non consecutive numbers
    
  7. Create a class with a main( ) that throws an object of class Exception inside a try block.

    a. Give the constructor for Exception a String argument.

    b. Catch the exception inside a catch clause and print the String argument.

    c. Add a finally clause and print a message to prove you were there.

  8. Write a program that will generate exceptions of type NegativeArraySizeException, IndexOutOfBoundsException, NullPointerException. Record the catching of each exception by displaying the message stored in the exception object.6


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages