You are on page 1of 1

Q1. Convert into Into Do while loop Q2.

Convert it into for Loop


for( int j = 3; j>=1; j--) { int i=99;
if (x==1) System.out.print (“One”); do {
else if (x==2) System.out.print (“Two”); System.out.println(“”+ i+10) ; i=i-3;
else if (x==3) System.out.print (“Three”); } } while (i<=33);
Q3. Rewrite it with For loop Q4. Rewrite it into for loop
int total , n , I ; int s=0;
n= Integer.parseInt(TextNo.getText()); while(s<=13) {
while( i< = n) { if (s%2==2) {
total =total + I; System.out.println(“color code red”); }
i=i+1; } else { System.out.println(“color code blue”); } System.out.println(“New color
code ”);
s=s+1; }
Q5. Rewrite it into for loop Q6. Find Output
int i=0; int compute(int x, int y) { //Assuming x>=0 and y>=0
while(++i<30) { If(x>=y) {
if(i==8) break; x=x-y;
sout(i++); } return compute(x,y) ; }
else { return x;}
}
Q7. Find Output Q8. Find Output
int x,y; double Number = 7583241;
for(x=1;x<=4;x++) int First = 0, Second = 0, R;
{ do {
for(y=1; y<=4;y++) R = Number % 10;
{ if ( R % 2 == 0 )
System.out.print(" "+x); First += R;
} else
System.out.println(); Second += R;
} Number = Number / 10;
} while (Number > 0);
System.out.print(First – Second );
Q9. Find Output Q10. Find Output
int i, j, k; int a;
for(i=1; i<=4; ++i) String b=”abcde”;
{ for(a=b.length();a>=0;a--)
for(k=1, j=I ; k<=I ; k++ , j+=2) {
System.out.printl(“ “,+j); System.out.println(b.substring(a));
System.out.println(“ “); }
}
Q11. Find Errors Q12. Find Errors
Class one switch(x)
{ Private int count; } {
Class two case 1 : n1 =10 ; n2 =20 ;
{ case 2 : n3 =30 ;
Public static void main (String args[]) break;
{ one ob = new one(); n1 =40 ;
ob.count=10; } }
Q13. Find Errors Q14. Find Errors
int m=100 int m=1;
while(m>0) int n=0;
{ for(;m+n<19; ++n)
if(m<10) System.out.println(“Hello \n”);
break; m=m+10;
m=m-10;
}
System.out.println(“m is “+m);
Q15. Find Errors Q16. Find Errors
int x=0; int i=0;
for(i=1; i<=10 ; j--) x=0;
{ while ( i < 10 )
System.put.print(“The j is “ + j) {
System.out.display(“The i is “ + i); if (i % 2 = 0)
} {
X=i+j; x == x + i ;
System.out.print(“The x is “ + x) } System.out.print(x + 1);
}
i++; }

You might also like