Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

UT - 2

Class - IX
SUB - WORKSHEET

Q) Answer the following Questions :


1) Predict the output and also mention the number of times the loop runs:
int a = 0;
while (a > -5)
{
System.out.print( a + “ “) ;
System.out.print(( -- a * 2) ) ;
System.out.println ( ) ;
--a ;
2) What will be the output of the following code :
(i ) public static void main(String args[ ])
{
int sum = 0 ;
for(int i =1 ;i < =5 ; i++)
{
sum = i ;
}
System.out.println (sum) ;
}
(ii ) for(k =100 ; k > 55 ; k = k – 5)
{
If (k % 2 = = 0)
{
continue ;
}
System.out.print(k + “ “ ) ;
}
3)(i) Differentiate between an empty loop and an infinite loop.
(ii ) Name two jump statements and write their uses.
(iii ) Explain for loop with the help of an example.
(iv) Distinguish between Math.rint( ) and Math.round( ) .
(v ) What is control variable in a switch statement ?
(vi ) What is a delay loop ? OR Why is null loop called delay loop ?

4) (i ) What are the components of a for loop?


(ii ) Write two differences between if else and switch – case constructs .
(iii ) What is the role of break statement in a loop ? Show a code example.
(iv ) What is the difference between Math.floor( ) and Math.ceil( ) ?
(v ) What is fall through ? Explain with an example .
Solve the following Java program :

1) Write a program 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 factors excluding 1 and the number
itself. Example – 4 , 6, 8 , 9 , …….
2) Write a Java Program to find the smallest digit of an integer that is input by user:
Sample input : 6524 , Sample output : Smallest digit is 2.
3) Write a menu driven program to calculate :
a)Area of circle = p * r2 , where p = 22 / 7.
b) Area of square = side * side.
c) Area of rectangle = length * breadth .
Enter ‘c ‘ to calculate area of circle , ‘s ‘ to calculate area of square and ‘r ‘ to calculate area of
rectangle.
4) Write a Java program to accept two numbers and find the Greatest Common Divisor (G.C.D) of
those numbers.
Sample Input : 25 , 45
Sample output : The Greatest Divisor : 5
5) Write a program to calculate the sum of all positive even numbers and sum of all negative odd
numbers from a set of numbers. The program should exit when a 0(zero) is entered.
6) Write a program to accept a number and check whether the number is a Palindrome or not.
(A palindrome number is a number that remains the same when its digits are reversed .For
example 18381).
7. Write a program to input a number (integer type ) . Print its factors.

You might also like