Grade 9 Computer Assignments - Guidelines - Term 2 (2025)
Grade 9 Computer Assignments - Guidelines - Term 2 (2025)
GRADE 9
(v) for(k=1;k<=2;k++)
{ for(m=1;m<=4;m++)
{ System.out.println(m*2);
}
}
How many times the inner loop is executed?
(a) 4 times (b) 8 times (c) 2 times (d) 16 times
Question 2.
Do as directed :
a. Classify the following as primitive or non-primitive datatypes:
(i) char (ii) arrays (iii) int (iv) object
b. Write the Java expression for the following :
√3𝑥 + 𝑥2
𝑎+𝑏
c. What is the value of y after evaluating the expression given below?
y+= ++y + y-- + -- y; when int y=8
d. Give the output of the following:
(i) Math.floor (-4.7)
(ii) Math.ceil(5.1) + Math.pow(3, 4)
Question 3.
Do as directed :
a. Write the output for the following:
System.out.println("Incredible"+ ‘\n’+"world");
b. Rewrite the following using ternary operator:if
(bill >10000)
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;
c. Convert the following if else if construct into switch case:
if( var==1)
System.out.println("good");
else if(var==2)
System.out.println("better");
else if(var==3)
System.out.println("best");
else
System.out.println("invalid");
d. Identify and name the following tokens:
(i) public (ii) '@' (iii) == (iv) {} (v) int a;
e. Give the output of following code and mention how many times theloop
will execute?
int i;
for( i=5 ; i>=1 ;i--)
{
if(i%2 ==1)
continue;
System.out.print( i+ '' '');
}
Question 4.
A tech number has even number of digits. If the number is split in two equal
halves, then the square of sum of these halves is equal to the number itself.
Write a program to generate and print all four digits technumbers.
Example:
Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2 = (55)2
= 3025 is a tech number.
Question 5.
Write a program to input a number and check and print whether it is a Pronic
number or not. (Pronic number is the number which is the productof two
consecutive integers)
Examples: 12 = 3 x 4
20 = 4 x 5
30 = 5 x 6
Question 6.
Write a program to print the sum of negative numbers, positive even numbers and
positive odd numbers from the list of N numbers entered bythe user. The list
terminates when the user enters 0 (zero).
Question 7.
Using the switch statement, write a menu driven program to:
(i) To find and display all the factors of a number input by the user
(including 1 and excluding number itself).
Example: Sample Input : n =15 Sample Output : 1,3, 5
(ii) To find and display the factorial of a number input by the user (the factorial
of a non– negative integer n, denoted by n!, is the product of allintegers less than
or equal to n. Example:
Sample Input : n =5 Sample Output :5! = 1×2×3×4×5 =120.
For an incorrect choice, an appropriate error message should be displayed.
Question 8.
Write a program to calculate and display the sum of the even numbers
in the range of A to B : Sample input : A = 4 and B = 12 then
Sum = 4 + 6 + 8 + 10 + 12
Question 9.
Write a program to accept a number and check and display whether it is an
Armstrong number or not. (Armstrong number is a number where sum of cube of
each digit is equal to the number).
Example :
Consider the number 153.
Sum of its digits is 13+53+33 = 153
Question 10.
WAP to accept a two digit number and check whether it is a Special two digit
number or not. A number is a Special two-digit number if sum of its digits +
product of the digits is equal to the number. E.g. 59 = 5+9 = 14 and 5*9=45.
14 + 45 = 59
Question 11.
Write a menu driven program to calculate and print the sum of the
following series according to user’s choice:
1. Sum (S) = 2 – 4 + 6 – 8 + ………. -20
2. Sum (s) = x + x + x + x + ………….. + x
2 5 8 11 20
(Value of x to be input by the user. )
Question 12.
Question 13.
Write a program to print the following pattern :
1
12
123
1234
12345
Question 14.
Write a program to print the following pattern :
ABCDE
ABCD
ABC
AB
A
Question 15.
Write a program to print the following pattern :
#
# @
# @ #
# @ # @