Page 213 - Cs_withBlue_J_C11_Flipbook
P. 213
break;
case 3:
int c = 20;
int d = 76;
break;
int e=c * d;
}
4. Rewrite the following code after making corrections.
int marks;
if(marks=1)
marks==90;
else if(marks=2)
marks=50;
5. Give the output of the following code fragment when:
(a) opn = ‘b’
(b) opn = ‘x’
switch(opn)
{
case 'a':
System.out.println("Simply Coding");
break;
case 'b':
System.out.println("Online Tutor");
case 'c':
System.out.println("Online Courses");
default:
System.out.println("Invalid Input");
}
6. Find the output of the following code fragment if n=10.
for(int i = 1;i<= n;i++)
{
if(n%i == 0)
System.out.println (i);
}
7. Find the output of the following code fragment if num1=8 and num2=10.
while(num1!= num2)
{
if(num1 > num2)
num1 = num1 - num2;
else
num2 = num2 - num1;
System.out.printf("GCD of given numbers is: "+num2);
}
#Coding & Computational Thinking
D. Unsolved Programs: #Digital Literacy
1. Write a Java program to input a number and print all the even digits and odd digits in the number separately.
2. Write a Java program to input a number and check whether it is divisible by 10 or not.
3. Write a Java program to print the following series:
th
a. 1+12+123+1234+……..+n term
b. S = a/1+a/2+c/3+…….+a/n
th
c. 1,4,9,16,……..., n term
d. 2+5+10+17+…….+n
th
e. 1*2*3*…….*n term
211
Statements and Scope 211

