Lab Questions: Presented By: Tekendra Nath Yogi
Lab Questions: Presented By: Tekendra Nath Yogi
Lab Questions: Presented By: Tekendra Nath Yogi
• write a java program to find max and min value from array of size 10.
• Write a java program to decide whether the input year is leap year or not (A
year is leap, if it is divisible by 4 and 400. But, not by 100.).
• Write a Java program to decide the grade of a student based on the marks
obtained by a student.
• Write Java program to search a number in a array. If found return the index.
• Write a java program to find the sum of array elements. Except the element at
index position 5.
11/23/2021 By: Tekendra Nath Yogi 3
Lab 2
• Write a java program to find the sum of array elements. If negative element is
found return the sum of previous elements of the array.
• Write a program to find the sum of the digits of a given integer number.
• Write a program with two arrays called height and weight for persons and then
count the numbers of persons with height>170 and weight<50.
• Write a program to find the number and sum of all integers greater than 100 and
less than 200 that are divisible by 7.
• Write a java program with a Employee class which has two data members id, name, age
and salary. Then create the object of the Employee class by new keyword and printing
the object's value. (Initialize the data members by reference, by member function, by
constructor) Write different program for each case.
• Write a Java program with a Rectangle class which has two data members length and
breadth. Use this class to find the area and perimeter of a rectangle.
• Write a Java program to demonstrate the working of a banking system where we deposit
and withdraw amount from your account. Create an Account class which has deposite( )
and withdraw( ) methods.
11/23/2021 By: Tekendra Nath Yogi 7
Lab 3
• Create a class Named Student with default constructor and parameterized constructors.
Use the constructors while making its object as pass a name of it and if nothing is
passed, then name should be "unknown". And finally display the name of student using
the printName( ) method.
• Write a Java program with a class named Box with data members length, breadth and
height of box, use constructor to set the value of these data members and use member
functions area, and volume to calculate the area and volume of corresponding box.
• Write a Java program with a class named Room with data members length, breadth and
height of box, use constructor to set the value of these data members and use member
functions area, and volume to calculate the area and volume of corresponding Room.
• Create a class named 'Student' with String variable 'name' and integer variable 'roll_no'.
Assign the value of roll_no as '2' and that of name as "John" by creating an object of the
class Student.
11/23/2021 By: Tekendra Nath Yogi 8
Lab 3
• Assign and print the roll number, phone number and address of two students having
names "Sam" and "John" respectively by creating two objects of class 'Student'.
• Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5
units by creating a class named 'Triangle' without any parameter in its constructor.
• Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5
units by creating a class named 'Triangle' with constructor having the three sides as its
parameters.
• Write a program to print the area of two rectangles having sides (4,5) and (5,8)
respectively by creating a class named 'Rectangle' with a method named 'Area' which
returns the area and length and breadth passed as parameters to its constructor.
• Write a program to print the area of a rectangle by creating a class named 'Area' having
two methods. First method named as 'setDim' takes length and breadth of rectangle as
parameters and the second method named as 'getArea' returns the area of the rectangle.
Length and breadth of rectangle are entered through keyboard.
• Add two distances in inch-feet by creating a class named 'AddDistance'.
• Print the sum, difference and product of two complex numbers by creating a class named
'Complex' with separate methods for each operation whose real and imaginary parts are
entered by user.
•
11/23/2021 By: Tekendra Nath Yogi 9
Lab 3
• Write a program to print the area of a rectangle by creating a class named 'Area' taking
the values of its length and breadth as parameters of its constructor and having a method
named 'returnArea' which returns the area of the rectangle. Length and breadth of
rectangle are entered through keyboard.
• Print the average of three numbers entered by user by creating a class named 'Average'
having a method to calculate and print the average.
• Write a Java program with a class Named Arithmetic (two integer numbers as its data
member and member functions for each arithmetic operation). Create objects of this
class and perform the various arithmetic operations on the data of each object.
• Write a Java program to call a super class constructors from the sub-class
constructor.
• Write a Java program to create a package, use the classes in the user defined
packages.
• Write a program with multiple catch blocks that are used to handle exceptions generated
by a single block of code.
• Write a program to illustrate the use of throw keyword to throw the exception explicitly.
• Write a program to throw your own exception (i. e. user define exception) and handle it.
• Write a java program to validate the age entered by user if age is more than 18 and
display appropriate message other wise throw an exception object with message “invalid
age” and display the message in exception object by the handler.(throw system
exception, throw custom exception).
11/23/2021 By: Tekendra Nath Yogi 13
Lab 6
• Write a java program with try catch block. Enclose the code that may generate
ArithmeticException in try block and resolve the exception in catch block.
• Write a java program to check student eligibility for registration. If student age is less
than 12 and weight is less than 40 then the student should get an ArithmeticException
with the warning message “Student is not eligible for registration”, other wise student
should get Student Entry is Valid message. throw the exception using throw keyword.
• Write a Java program to throw custom exception explicitly using throw keyword in
combination with throw keyword in combination with throws keyword when employee
age is negative.
• Write a Java program to illustrate the exception propagation using throws keyword.
• Create a CheckingAccount class containing deposit() and withdraw() method that throws
an InsufficientFundsException in case of withdraw if the amount to be withdrawn is
greater than the total amount in the account..
• Write a Java Program to find the frequency of each element in the array.
• Write a Java Program to print the elements of an array present on even position.
• Write a Java Program to print the elements of an array present on odd position.
• Write a Java Program to print the sum of all the items of the array.
• Write a Java Program to Print Odd and Even Number from an Array.
• Write a Java Program to find the frequency of odd & even numbers in the given matrix.
• Write a Java Program to find the sum of each row and each column of a matrix.
• Write a java program to find the sub-string Ram in the string HariRamBahadur.