Write the output and if there is an error correct the error first then write the outp:
1.for(int i=-3; i<19; i=i+3)
{
out.print(i + " ");
}
2.for(int j=17; j>-2; j=j-2)
{
out.print(j + " ");
}
3.for(int x=20, x<50, x=x+3)
{
out.print(x + " ");
}
4.for(m=37; m>0; m=m-4)
{
out.print(m + " ");
}
5.int total=0;
for(int s=1; s<19; s++)
{
total=total+s;
}
out.println(total);
6.int x=-2;
while(x<9)
{
x++;
System.out.print(x + " ");
}
7.int m=1, total=0;
while(m<9){
total=total+m;
m++;
}
System.out.print(total );
8.int k=5;
String s="";
while(k>0){
s=k+" "+s;
k--;
}
System.out.print(s);
9.int b=3;
String list="";
while(b<10) {
b=b+2;
if(b%2==1)
list=b+" "+list;
}
System.out.print(list);
10.int num = 15, MAX = 20;
do
{
num = num + 1;
System.out.println (num);
} while (num <= MAX);
11.int num = 15, MAX = 20;
do
{
num = num + 1;
if (num*2 > MAX+num)
System.out.println (num);
}
while (num <= MAX);
1.error
correct:
for(int i=-3; i<19; i=i+3)
{
System.out.print(i + " ");
}
output:-3 0 3 6 9 12 15 18
2.error
correct:
for(int j=17; j>-2; j=j-2)
{
System.out.print(j + " ");
}
output:17 15 13 11 9 7 5 3 1 -1
3.error
correct:
for(int x=20; x<50; x=x+3)
{
System.out.print(x + " ");
}
output:20 23 26 29 32 35 38 41 44 47
4.error
correct:
for(int m=37; m>0; m=m-4)
{
System.out.print(m + " ");
}
output:37 33 29 25 21 17 13 9 5 1
5.error
correct:
int total=0;
for(int s=1; s<19; s++)
{
total=total+s;
}
System.out.println(total);
output:171
6.correct
output:-1 0 1 2 3 4 5 6 7 8 9
7.correct
output:36
8.correct
output:1 2 3 4 5
9.correct
output:11 9 7 5
10.correct
output:16
17
18
19
20
21
11.correct
output:21
Comments
Leave a comment