Practice Sheet-1
Java Basics (Print Statement)
1. Write a Java program to print 'Hello' on screen and then print your name on
a separate line.
Expected Output :
Hello
Sterling Institute
2. Write a Java program to print the sum of two numbers.
Test Data:
74 + 36
Expected Output :
110
3. Write a Java program to divide two numbers and print on the screen.
Test Data :
50/3
Expected Output :
16
STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
4. Write a Java program to print the result of the following operations.
Test Data:
i. -5 + 8 * 6
ii. (55+9) % 9
iii. 20 + -3*5 / 8
iv. 5 + 15 / 3 * 2 - 8 % 3
Expected Output :
43
1
19
13
5. Write a Java program to display the following pattern.
Sample Pattern :
J a v v a
J a a v v a a
J J aaaaaa v v aaaaaa
J J a a v a a
6. Write a Java program to compute the specified expressions and print the
output.
Test Data:
((25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5))
Expected Output
2.138888888888889
STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
7. Write a Java program to print an American flag on the screen.
Expected Output
* * * * * * ==================================
* * * * * ==================================
* * * * * * ==================================
* * * * * ==================================
* * * * * * ==================================
* * * * * ==================================
* * * * * * ==================================
* * * * * ==================================
* * * * * * ==================================
==========================================
==========================================
==========================================
==========================================
==========================================
8. Write a program to print the Hollow Pyramid Star Pattern?
*
* *
* *
* *
* * * * * * * * *
STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
9. Write a program to print Inverted Pyramid Star Pattern?
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
10.Write a program to print Half Diamond Star Pattern?
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
11.Write a program to print Hollow Diamond Star Pattern?
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in
12.Write a program to print Plus Star Pattern?
+
+
+
+
+ + + + + + + + +
+
+
+
+
13.Write a program to print X Star Pattern?
* *
* *
* *
*
* *
* *
* *
14.Write a program to print A Star Pattern?
*
* *
* * * * *
* *
* *
STERLING INSTITUTE
G-5, 150 New Azad Nagar Behind Akashwani, Daly College Road Indore – 452001
Contact: +91 9109913455
www.sterlinginstitute.in