Class IX
Revision Booklet
Section A
1. Distinguish between Math.ceil() and Math.floor() methods.
2. What is a java package? Give an example.
3. Distinguish between the following:
a. next() and nextLine()
b. next() and next().charAt(0)
4. Explain the following terms, giving an example of each.
a. Syntax error
b. Runtime error
c. Logical error
5. How are these statements different from each other:
a. break
b. continue
c. System.exit(0)
6. What are the differences between while loop and do-while loop?
7. How many times are the following loop bodies repeated? What is the final output in
each case?
8. How many times are the following loop bodies repeated? What is the final output in
each case?
9. Explain the role of return statement in a method?
10. What is a token in Java? Name the tokens available in Java.
11. Describe primitive data types in Java.
12. What is an assignment operator? Give an example.
13. State the difference between = and ==.
14. If a = 5, b = 9, calculate the value of:
a += a++ - ++b + a
15. What is type conversion? How is an implicit type conversion different from an
explicit type conversion?
Section B
1. Write a program in Java that accepts the seconds as input and converts them into the
corresponding number of hours, minutes and seconds. A sample output is shown
below:
Enter Total Seconds:
5000
1 Hour(s) 23 Minute(s) 20 Second(s)
2. Write a program in java to input the temperature in Fahrenheit, convert it into Celsius
and display the value in the Terminal window. A sample output is displayed below:
Enter temperature in Fahrenheit: 176
176.0 degree Fahrenheit = 80.0 degree Celsius
3. Write a program to generate random integers in the range 10 to 20.
4. Write a program in Java to compute the perimeter and area of a triangle, with its three
sides given as a, b, and c using the following formulas:
5. Mayur Transport Company charges for parcels as per the following tariff:
Write a program in Java to calculate the charge for a parcel, taking the weight of the
parcel as an input.
6. Write a menu-driven program to accept a number from the user and check whether it
is a Buzz number or an Automorphic number.
a. Automorphic number is a number, whose square's last digit(s) are equal to that
number. For example, 25 is an automorphic number, as its square is 625 and
25 is present as the last two digits.
b. Buzz number is a number, that ends with 7 or is divisible by 7.
7. A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies.
Write a program that prompts the user to enter the total number of cookies, the
number of cookies in each box, and the number of cookie boxes in a container. The
program then outputs the number of boxes and the number of containers required to
ship the cookies.
8. A special two-digit number is such that when the sum of its digits is added to the
product of its digits, the result is equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits = 5 + 9 = 14
Product of digits = 5 * 9 = 45
Sum of the sum of digits and product of digits = 14 + 45 = 59
Write a program to accept a two-digit number. Add the sum of its digits to the product
of its digits. If the value is equal to the input number, display the message "Special 2-
digit number" otherwise, display the message "Not a special two-digit number".
9. Using the switch statement, write a menu-driven program:
a. To check and display whether a number input by the user is a composite
number or not. A number is said to be composite if it has one or more than one
factor excluding 1 and the number itself. Example: 4, 6, 8, 9...
b. To find the smallest digit of an integer that is input:
Sample input: 6524
Sample output: The smallest digit is 2
For an incorrect choice, an appropriate error message should be displayed.
10. Write a program to display all the numbers between 100 and 200 which don't contain
zeros at any position.
11. Write a program to display all prime palindrome numbers between 10 and 1000.
[Hint: A number that is prime as well as a palindrome is said to be a 'Prime
Palindrome.]
For example: 11, 101, 131, 151,
12. Write a program in Java to enter a number containing three digits or more. Arrange
the digits of the entered number in ascending order and display the result.
Sample Input: Enter the number 4972
Sample Output: 2, 4, 7, 9
13. Write a program to input a number and display only those factors of the numbers that
are prime.
Sample Input: 84
Sample Output: 2, 3, 7
14. Write a program using do-while loop to compute the sum of the first 50 positive odd
integers.
15. Write a program to read the number n via the Scanner class and print the Tribonacci
series: 0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81 ...and so on.
Hint: The Tribonacci series is a generalisation of the Fibonacci sequence where each
term is the sum of the three preceding terms.
16. Write a program to input a number and check and print whether it is a Pronic number
or not. (Pronic number is a number that is the product of two consecutive integers.)
17. Write a program to accept a number and check and display whether it is a Niven
number or not. (Niven number is a number which is divisible by the sum of its
digits).
Example:
Consider the number 126.
Sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9.
18. Write a menu-driven program to access a number from the user and check whether it
is a
a. BUZZ number or to accept any two numbers and print the GCD of them. A
BUZZ number is a number that either ends with 7 or is divisible by 7.
b. GCD (Greatest Common Divisor) of two integers is calculated by the
continued division method. Divide the larger number by the smaller; the
remainder then divides the previous divisor. The process is repeated till the
remainder is zero. The divisor then results from the GCD.
19. Write a program to generate the following output:
20. Write a program in Java to display the following patterns:
21. Write a program in Java to display the following patterns.
22. Write a program to input two numbers and check whether they are twin prime
numbers or not.
Hint: Twin prime numbers are the prime numbers whose difference is 2.
For example: (5,7), (11,13), ....... and so on.
23. Write a program to generate a triangle or an inverted triangle till n terms based upon
the user's choice.
Example 1:
Input: Type 1 for a triangle and
Type 2 for an inverted triangle
Enter your choice 1
Enter the number of terms 5
Sample Output:
1
22
333
4444
55555
Example 2:
Input: Type 1 for a triangle and
Type 2 for an inverted triangle
Enter your choice 2
Enter the number of terms 6
Sample Output:
666666
55555
4444
333
22
1
24. Write a program to enter two numbers and check whether they are co-prime or not.
[Two numbers are said to be co-prime, if their HCF is 1 (one).]
Sample Input: 14, 15
Sample Output: They are co-prime.
25. Write a program to input a number. Display the product of the successors of even
digits of the number entered by the user.
Input: 2745
Output: 15
[Hint: The even digits are: 2 and 4
The product of the successor of even digits is 3*5= 15]