Professional Documents
Culture Documents
Prac 9th Comp UT2 - 1
Prac 9th Comp UT2 - 1
[2 x 5]
1. int a;
for(a=1;a<=15;a+=3)
{
if(a%5==0)
break;
System.out.println(a);
}
2. int a;
for(a=1;a<=15;a+=3)
System.out.println(a++);
3. int a;
for(a=2;++a<=10;a+=2)
System.out.println(a+1);
4. int a;
for(a=1;a<=5;a++)
{
if(a%2!=0)
continue;
System.out.println(a);
}
5. switch(a)
{
case 1: System.out.println(“Apple”);
case 2: System.out.println(“Mango”);
case 3: System.out.println(“Grapes”);
default: System.out.println(“Banana”);
}
What will be the output if (i) int a = 2; (ii) int a = 4;
B. Do as directed. [2 x 5]
1. Give an example of infinite loop.
2. Write a loop to display ‘Z’ to ‘A’.
3. Write a loop to count and display how many three digit numbers are there which end with a zero.
4. An integer variable N contains a positive number. Write a loop to display its factors and also sum of those factors.
5. Re-write the following using if else.
switch(a)
{
case 1:
case 2: System.out.println(“Top Two”); break;
case 3: System.out.println(“Third”); break;
default: System.out.println(“Rest Others”);
}