1.
Write Java program to Print the following triangle of numbers
1
12
123
1234
12345
2. Write a java program to read 3 subject marks, Calculate total and average marks.
Display the grade based on the following criteria:
Note: Percentage>=90%: Grade A, Percentage>=80%: Grade B, Percentage>=70%:
Grade C, Percentage>=60%: Grade D, Percentage>=40%: Grade E.
3. Write a Java program to create a class called Person with p_name and age. Which
includes constructor to initialize these fields and a method to display the person
information. In the main method, an instance of the person class will be created and
person information is displayed.
4. Define a class named Animal with two methods: eat () and sleep (). Create a class
named Dog that extends the Animal which includes a method called bark() and also
create class Cat that extends Animal which includes meow () method. Create a class
called MainClass to write main () method and demonstrate the following:
Inside the main method:
a. Create objects of the Dog and Cat classes (myDog and myCat)
b. Demonstrate calling methods from the parent class (eat () and sleep ())
c. Illustrate calling methods from the Dog class (bark ())
d. Showcase calling methods from the Cat class (meow ())
5. Write a Java program that prompts the user to enter a number between 1 and 7. The
program then uses a switch case statement to determine the corresponding day of
the week based on the user’s input and prints the result.
6. Create Shape class serves as the base class for all shapes. It contains a method draw
() that prints a generic message indicating the act of drawing a shape. The Circle class
extends the shape class and overrides the draw () method to provide a specialized
implementation, for drawing a circle. Similarly, the square class extend the Shape
class and provides its own implementation of the draw method () to handle drawing
square. Create a Main class contains the main method serving as the entry point of
the program. Two objects, shape1 and shape2 are declared of type Shape but
instatiated as Circle and Square objects, respectively. This demonstrates the
polymorphic behaviour, allowing objects of the base class.
7. A) Write a Java program to Calculate the factorial of given number n.
B) Write a Java program to Check given String is Palindrome or not.
8. Create a user defined package named shapes containing a class circle with a method to
calculate area of circle. Create a separate class to access this package and display the area.