You are on page 1of 5

Java Questions

1. Write a java program (WJP) to print Hello World without using


System.out.println () method.
2. WJP to read two numbers using Scanner class, 10 more numbers
using command line arguments, and 10 numbers using
BufferedReader class, Print sum of those 22 numbers.
3. WJP to read all types of data (int, float, double, long, short, byte,
char, boolean) and to print it.
4. Read two integers a and b, two floating point numbers p and q,
Do the following on a and b,
min(), max(), ab, ba, and all arithmetic operations.
Do the following on p and q,
floor(), ceil(), abs(), round() and some other operations defined
in Math class.
5. WJP to read two Strings S1 and S2,
And perform the following operations on S1 and S2,
a. Length()
b. Concat them using, concat(), and + symbol
c. Print Character at some index
d. Compare them using both compareTo() and equals().
e. Print hashcodes of S1 and S2.
f. Find whether S2 is a substring of S1 or not, if yes, then print
its starting index in S1.
g. Replace all consonants in S1 with the letter z( replaceAll()).
h. Print substrings of S1, S2 from index 0 to 5.
i. Convert S1 to upper case and S2 to lower case.
6. WJP to compare two numbers using if-else-if.
7. Demonstrate use of &, |, ~, ^ and &&, ||,! Operators.
8. WJP to find greatest of two numbers using conditional operator.
9. Demonstrate use of =, +=, -=, /=, *=, ++, --, instance of operators.
10. Read a character, print the name colour it represents in
VIBGYOR, using switch statement. Ex: if ch ==V print VIOLET
11. Print greatest of three numbers using nested if-else.
12. Read the CGPA of a student in 6 semesters, and print Average
CGPA for it using for-loop.
13. Print Fibonacci series using while-loop.
14. Print Factorial of a number using do-while loop.
15. using any of the three loops print the following,
*
**
***
****
*****
16. take an array of elements, and iterate through each element
using enhanced for loop.
17. create a class, and define three methods methodA(),
methodB(), methodC() such that,
methodA() should be accessed globally,
methodB() should be accessed only in the current package
and the child class
method() should be accessed only in its class.
18. Create a class which cannot be extended, a method which
cannot be overridden and a variable whose value cannot be
changed.
19. print hello world in the console before the main method
executes( static block).
20. swap two numbers using methods and print the result
whether they are swapped or not.
21. write a method sum(type a, type b), such that it should be
able to add two integers, two floating point numbers, two long
numbers, two short numbers, two double numbers, and two
byte numbers(hint: method overloading).
22. define a class Volume, in that create constructors as
following,
Volume(int side) - > to calculate volume of a cube
Volume(double radius) -> to calculate volume of a sphere
Volume(int height, double radius) -> calculate volume of a cone
Volume(int length, int breadth, int height) -> area of cuboid

Define four methods to calculate areas of cube, sphere, cone,


and cuboid and call them from the appropriate constructor.
Print the answer for the following
Volume of a cube whose side is 15
Volume of a sphere whose radius is 13.23
Volume of a cone whose height and radius are 12, 5.48
Volume of a cone whose l, b, h are 20, 34, 45.
23. sort an array and find whether a number 2 exists in it or not
using Arrays class.
24. Create a file and write something into it using PrintWriter
class and read the same content using Scanner class.
25. WJP to handle exceptions using try-catch block, throw
keyword, and throws keyword.
26. Solve problem-12 using methods.
27. Solve problem-15 using methods.
28. Solve problem-13,14 using recursion.
29. Create a package for all the above files
Package name com.java.parctice
30. Demonstrate use of Inner class and access the private
variables of outer class in the inner class.
31. Print current date and time in the following format,
Date : dd/mmm/yyyy
Time: hh:mm:ss
32. Create an array list, and do the following operations on it,
a. add 1
b. add 3.45
c. add(this is java)
d. print list
e. add 342 at 2nd index
f. set value at index 1 to 541
g. print list
h. add(this is java)
i. add(c)
j. add 345634245353
k. remove element at index 4
l. remove element at index 3
m. add 3.45
n. add 342
o. add 1
p. print list
33. Do above operations on a linked list
34. Do above operations on a set( HashSet, TreeSet)
35. Take an index page of a book, and create a map for it in java
Ex: map is (Key, value)
For book (chaptername, page no.)

You might also like