CSE110 – Trace the output of the following programs Solved

$ 24.99
Category:

Description

In the following tasks, First, save->compile->run it in Dr. Java / Jeilot and Then, trace the output of the code by hand Try to matching each of your manual output with output shown in DrJava / Jeliot
public class Q1
{
public static void main(String[] args)
{
int x = 0, y =0; int sum = 0; while (x < 10){ y = x – 3; y = 40; while (y > 22){ if ((sum > 30) && (sum < 40)) sum = sum + x * 2 ; else if ((sum > 40) && (sum < 50)) sum = sum + x * 3; else
sum = sum + 23; System.out.println(sum); y = y – 10;
} x += 2;
}
} }
1 public class Q2
2 {
3 public static void main(String[] args)
4 {
5 String test = “”;
6 int i = 0, j = 0, k = 15;
7 while (i< 5){
8 test = “–>”;
9 j = –k;
10 while (j > 10 ){
11 test = i + j + test + i + j;
12 System.out.println(test);
13 j–;
14 }
15 i++;
16 }
17 }
18 }

1 public class Q3{
2 public static void main(String[] args){
3 int x = 0, y =0;
4 int sum = 0;
5 while (x < 10){
6 y = x – 3;
7 while (y < 3){
8 sum = (sum % 2) + x – y * 2 ;
9 System.out.println(sum);
10 y = y + 1;
11 }
12 if (x > 5){
13 x++;
14 }else{
15 x += 2;
16 }
17 }
18 }
19 }

1 public class Q4{
2 public static void main(String[] args){
3 int x = 0, i =0, sum = 0;
4 i = 1;
5 x = 2;
6 sum = 0;
7 while (i< 20){
8 x = x + i;
9 sum = sum + x + 1;
10 System.out.println(sum);
11 if (x > 5)
12 i += 2;
13 else
14 i += 3;
15 }
16 sum = sum + i;
17 System.out.println(sum);
18 }
19 }

1 public class Q5{
2 public static void main(String[] args){
3 String test = “”;
4 int i = 0, j = 0, k = 15;
5 test = “–>”;
6 while (i< 5){
7 j = –k;
8 while (j > 10 ){
9 test = i + j + “–>” + test;
10 System.out.println(test);
11 j–;
12 }
13 i++;
14 }
15 }
16 }

1 public class Q6{
2 public static void main(String[] args){
3 int x = 0, p =0, sum = 0;
4 p = 1;
5 x = 2;
6 double q;
7 sum = 0;
8 while (p < 10){
9 q = x + p-(sum+5/3)/3.0%2 ;
10 sum = sum + (x++) + (int)q;
11 System.out.println(sum);
12 if (x > 5)
13 p += 4/2;
14 else
15 p += 3%1;
16 }
17 sum = sum + p;
18 System.out.println(sum);
19 }
20 }

1 public class Q7{
2 public static void main(String[] args){
3 int test = 1;
4 int j = 0, k = 100;
5 while (k > 0){
6 while (j < k ){
7 test = k – j + 21;
8 System.out.println(1 + test);
9 j += 10;
10 }
11 k -= 10;
12 }
13 }
14 }

1 public class Q8{
2 public static void main(String[] args){
3 int test = 1;
4 int j = 0, k = 100;
5 while (k > 0){
6 while (j < k ){
7 test = k – j + 11;
8 System.out.println(1 + test / 3 +”12″);
9 j+=10;
10 }
11 k-=10;
12 }
13 }
14 }

1 public class Q9{
2 public static void main(String[] args){
3 int x = 0;
4 int y = 0;
5 int sum = 0;
6 double p;
7 while(x <18){
8 y = x / 2;
9 while(y < x){
10 p = (x + 15.0) /2;
11 sum = (sum + 3) + x + y * 3 + (int)p;
12 System.out.println(sum);
13 y = y + 3;
14 }
15 x = x + 3;
16 }
17 }
18 }

1 public class Q10 {
2 public static void main(String[] args) {
3 int x = 0, y = 0;
4 String sum = “0”;
5 double p;
6 while (x < 9) {
7 y = x / 2;
8 while (y < x) {
9 p = (x + 5.0) / 2;
10 sum = (sum + 2) + x + “y * 2” + (int) p ;
11 System.out.println(sum);
12 y = y + 1;
13 }
14 x = x + 2;
15 if (x > 5) {
16 sum = “2”;
17 } else {
18 sum += “3”;
19 }
20 }
21 }
22 }

1 public class Q11 {
2 public static void main(String[] args) {
3 String test = “”;
4 int i = 1, j = 1, k = 14;
5 test = “–>”;
6 while (i< 5) {
7 j = –k;
8 while (j > 9 ) {
9 test = i + (j-2) + “–>” + test;
10 System.out.println(test);
11 j–;
12 }
13 i++;
14 }
15 }
16 }

1 public class Q12 {
2 public static void main(String[] args) {
3 int p = 5;
4 int q = 6;
5 int r = 9;
6 int sum = 0;
7 if (p < 12) {
8 System.out.println(r + 2);
9 } else {
10 System.out.println(r + p);
11 }
12
13 if (q > 20){
14 System.out.println(r + 19);
15 } else if (q <= 6) {
16 System.out.println(q + 3);
17 } else{
18 System.out.println(p + q + r);
19 }
20
21 if (r > 15) {
22 System.out.println(r);
23 } else if (r == 0) {
24 System.out.println(p + q);
25 } else {
26 System.out.println(p);
27 }
28
29 if (sum != 0) {
30 System.out.println(3);
31 } else {
32 System.out.println(sum + 32);
33 }
34
35 if(p > 0 && r < 10){
36 System.out.println(p + r);
37 } else {
38 System.out.println(p – r);
39 }
40 }
41 }

1 public class Quiz13 {
2 public static void main(String[] args){
3 int x = 0, p = 0, sum = 0;
4 p = 1;
5 x = 2;
6 double q;
7 sum = 0;
8 while (p < 10) {
9 q = x + p-(sum+5/3)/3.0%2 ;
10 sum = sum + (x++) + (int)q;
11 System.out.println(sum);
12 if (x > 5)
13 p += 4/2;
14 else
15 p += 3%1;
16 }
17 sum = sum + p;
18 System.out.println(sum);
19 }
20 }

1 public class Q14 {
2 public static void main(String[] args) {
3 int x = 0, i =0, sum = 0;
4 i = 1;
5 x = 2;
6 sum = 0;
7 while (i< 20){
8 x = x + i;
9 sum = sum + x + 1;
10 System.out.println(sum);
11 if (x > 5)
12 i += 2;
13 else
14 i += 3;
15 }
16 sum = sum + i;
17 System.out.println(sum);
18 }
19 }

1 public class Q15 {
2 public static void main(String[] args) {
3 int x = 0, y =0;
4 int sum = 0;
5 while (x < 10){
6 y = x – 3;
7 y = 40;
8 while (y > 22){
9 if ((sum > 30) && (sum < 40))
10 sum = sum + x * 2 ;
11 else if ((sum > 40) && (sum < 50))
12 sum = sum + x * 3;
13 else
14 sum = sum + 23;
15 System.out.println(sum);
16 y = y – 10;
17 }
18 x += 2;
19 }
20 }
21 }

1 public class Q16 {
2 public static void main(String[] args) {
3 boolean var1=false, var2=false, var3=false, var4=false,var5=false;
4 boolean var6=false, result1=false, result2=false, result3=false, result4=false;
5 boolean result5=false, result6=false, result7=false, result8=false;
6 boolean result9=false, result10=false;
7 var1=4 > 3 – 1;
8 var2=var1 && false;
9 var3=true;
10 var4=false;
11 var5=true;
12 var6=var3 && false;
13 result1=(var1 || var2) && (8 * 10 > 45);
14 result2=(var1 || var2) && (result1 && false);
15 result3=(var1 && result1) || result2;
16 result4=(var1 || var2) || ((var3 && var1) && false);
17 result5=(var1 && var2) && (result3 || var1);
18 result6=((var3 || var2) && !(result5)) || true;
19 result7=(var4 && result1) && ((result1 && false) || true);
20 result8=((var1 && result3) && (var5 || var6)) && true;
21 result9=((result2 && var2) || (result7 && var1)) && false;
22 result10=!(var1 && true);
23 }
24 }
Show the values of the result variables in the above program:

result1
result2
result3
result4
result5
result6
result7
result8
result9
result10

1 public class Q17 {
2 public static void main(String[] args) {
3 int x = 0, i = 0, sum = 0;
4 i = 1;
5 x = 2;
6 sum = 0;
7 while (i< 20) {
8 x = x + i;
9 sum = sum + x + 3;
10 System.out.println(sum);
11 if (x > 5)
12 i += 2;
13 else
14 i += 3;
15 }
16 sum = sum + i;
17 System.out.println(sum);
18 }
19 }
1 public class Q18 {
2 public static void main(String[] args) {
3 int x = 0, y =0;
4 int sum = 0;
5 while (x < 10){
6 y = x – 3;
7 y = 40;
8 while (y > 22){
9 if ((sum > 30) && (sum < 40))
10 sum = sum + x * 3 ;
11 else if ((sum > 40) && (sum < 50))
12 sum = sum + x * 4;
13 else
14 sum = sum + 24;
15 System.out.println(sum);
16 y = y – 10;
17 }
18 x += 2;
19 }
20 }
21 }

1 public class Q19 {
2 public static void main(String[] args) {
3 boolean var1=false, var2=false, var3=false, var4=false,var5=false;
4 boolean var6=false, result1=false, result2=false, result3=false, result4=false;
5 boolean result5=false, result6=false, result7=false, result8=false;
6 boolean result9=false, result10=false;
7 var1=4 < 3 – 1;
8 var2=var1 && false;
9 var3=false;
10 var4=true;
11 var5=false;
12 var6=var3 && true;
13 result1=(var1 || var2) && (8 * 10 > 45);
14 result2=(var1 || var2) && (result1 && false);
15 result3=(var1 && result1) || result2;
16 result4=(var1 || var2) || ((var3 && var1) && false);
17 result5=(var1 && var2) && (result3 || var1);
18 result6=((var3 || var2) && !(result5)) || true;
19 result7=(var4 && result1) && ((result1 && false) || true);
20 result8=((var1 && result3) && (var5 || var6)) && true;
21 result9=((result2 && var2) || (result7 && var1)) && false;
22 result10=!(var1 && true);
23 }
24 }
Show the values of the result variables in the above program:
result1
result2
result3
result4
result5
result6
result7
result8
result9
result10

1 public class Q20 {
2 public static void main(String[] args) {
3 int x = 0, y =0;
4 int sum = 0;
5 while (x < 10) {
6 y = x – 3;
7 while (y < 3) {
8 sum = x – y * 2 ;
9 System.out.println(sum);
10 y = y + 1;
11 }
12 if (x > 7) {
13 x++;
14 } else {
15 x += 3;
16 }
17 }
18 sum = x – y * 2 ;
19 System.out.println(sum);
20 }
21 }

1 public class Q21 {
2 public static void main(String[] args) {
3 int x = 0, y =0;
4 int sum = 0;
5 while (x < 10) {
6 y = x – 3;
7 while (y < 3) {
8 sum = x – y * 3 ;
9 System.out.println(sum);
10 y = y + 1;
11 }
12 if (x > 7) {
13 x++;
14 } else {
15 x += 3;
16 }
17 }
18 sum = x – y * 3 ;
19 System.out.println(sum);
20 }
21 }

1 public class Q22 {
2 public static void main(String[] args) {
3 int x = 0, y =0;
4 int sum = 0;
5 while (x < 10) {
6 y = x – 3;
7 y = 40;
8 while (y > 22) {
9 if ((sum > 30) && (sum < 40))
10 sum = sum + x * 2 ;
11 else if ((sum > 40) && (sum < 50))
12 sum = sum + x * 3;
13 else
14 sum = sum + 23;
15 System.out.println(sum);
16 y = y – 10;
17 }
18 x += 2;
19 }
20 }
21 }

1 public class Q23 {
2 public static void main(String[] args) {
3 int x = 0, y = 0;
4 int sum = 0;
5 while (x < 10) {
6 y = x – 3;
7 y = 40;
8 while (y > 22) {
9 if ((sum > 30) && (sum < 40))
10 sum = sum + x * 3 ;
11 else if ((sum > 40) && (sum < 50))
12 sum = sum + x * 4;
13 else
14 sum = sum + 24;
15 System.out.println(sum);
16 y = y – 10;
17 }
18 x += 2;
19 }
20 }
21 }

1 public class Q24 {
2 public static void main(String[] args) {
3 int x = 0, p = 0, sum = 0;
4 p = 1;
5 x = 2;
6 double q;
7 sum = 0;
8 while (p < 12){
9 q = x + p-(sum+5/3)/3.0%2 ;
10 sum = sum + (x++) + (int)q;
11 System.out.println(sum);
12 if (x > 5)
13 p += 4/2;
14 else
15 p += 3%1;
16 }
17 sum = sum + p;
18 System.out.println(sum);
19 }
20 }

1 public class Q25 {
2 public static void main(String[] args) {
3 int test = 1;
4 int j = 0, k = 100;
5 while (k > 0) {
6 while (j < k ) {
7 test = k + j – 21;
8 System.out.println(1 + test / 2 +”32″);
9 j+=10;
10 }
11 k-=10;
12 }
13 }
14 }

1 public class Q26 {
2 public static void main(String[] args) {
3 String test = “”;
4 int i = 5, j = 0, k = 15;
5 while (i< 10){
6 k -= 1;
7 j = k;
8 while (j > 10 ) {
9 if (j % 2 == 0) {
10 test = “<–“;
11 test = test + i + 2 + “–>” + (j / 2);
12 } else {
13 test = “–>”;
14 test = “–>” + (i / 2) + test + j;
15 }
16 System.out.println(test);
17 –j;
18 }
19 i++;
20 }
21 }
22 }

1 public class Q27 {
2 public static void main(String[] args) {
3 int x = 0, p = 0, sum = 0;
4 p = 1;
5 x = 2;
6 double q;
7 sum = 0;
8 while (p < 12) {
9 q = x + p-(sum+7/3)/3.0%2 ;
10 sum = sum + (x++) + (int)q;
11 System.out.println(sum);
12 if (x > 5)
13 p += 4/2;
14 else
15 p += 3%1;
16 }
17 sum = sum + p;
18 System.out.println(sum);
19 }
20 }

public class Q28 {
public static void main(String[] args) {
int test = 1;
int j = 0, k = 100;
while (k > 0){
while (j < k ){
test = k – j + 21;
System.out.println(1 + test / 2 +”11″);
j+=10;
}
k-=10;
}
}
}

public class Q29 {
public static void main(String[] args) {
String test = “”;
int i = 5, j = 0, k = 15;
while (i< 10){
k -= 1;
j = k;
while (j > 10 ){
if (j % 2 == 0){
test = “<–“;
test = test + i + 3 + “–>” + (j / 3);
}else{
test = “–>”;
test = “–>” + (i / 3) + test + j ;
}
System.out.println(test);
–j;
}
i++;
}
}
}

public class Q30 {
public static void main(String[] args) {
String test = “”;
int i = 0, j = 0, k = 15;
test = “<–cat”;
while (i< 5){
k-=1;
j = k;
while (j > 10 ){
if (j % 2 == 0){
test += “–>”;
test = test + i + (j / 2);
}else{
test += “<–“;
test = test + (i / 2) + j;
}
System.out.println(test);
–j;
}
i++;
}
}
}

public class Quiz31 {
public static void main(String[] args) {
String test = “”;
int i = 2, j = 0, k = 17;
test = “–>dog”;
while (i< 7){
k-=1;
j = k;
while (j > 12 ){
if (j % 2 == 0){
test += “<–“;
test = test + i + (j / 2);
}else{
test += “–>”;
test = test + (i / 2) + j;
}
System.out.println(test);
–j;
}
i++;
}
}
}

public class Q32 {
public static void main(String[] args) {
int x = 0, y = 0;
int sum = 0;
double p;
while (x < 10) {
y = x / 2;
while (y < x) {
p = (x + 10.0) / 2;
sum = (sum % 2) + x – y * 2 + (int) p ;
System.out.println(sum);
y = y + 2;
}
if (x > 5) {
x++;
} else {
x += 2;
}
}
}
}

public class Q33 {
public static void main(String[] args) {
int x = 0, y =0;
int sum = 0;
double p;
while (x < 10) {
y = x / 2;
while (y < x) {
p = (x + 5.0) / 2;
sum = (sum % 2) + x – y * 2 + (int) p ;
System.out.println(sum);
y = y + 2;
}
if (x > 5) {
x++;
} else {
x += 2;
}
}
}
}

public class Q34 {
public static void main(String[] args) {
int x = 0, p = 0, sum = 0;
p = 1;
x = 2;
double q;
sum = 0;
while (p < 12){
q = x + p-(sum+5/3)/3.0%2 ;
sum = sum + (x++) + (int)q;
System.out.println(sum);
if (x > 5)
p += 4/2;
else
p += 3%1;
}
sum = sum + p;
System.out.println(sum);
}
}

public class Q35 {
public static void main(String[] args) {
int test = 1;
int j = 0, k = 100;
while (k > 0){
while (j < k ){
test = k + j – 21;
System.out.println(1 + test / 2 +”32″);
j+=10;
}
k-=10;
}
}
}

public class Q36 {
public static void main(String[] args) {
String test = “”;
int i = 5, j = 0, k = 15;
while (i< 10) {
k-=1;
j = k;
while (j > 10 ) {
if (j % 2 == 0) {
test = “<–“;
test = test + i + 2 + “–>” + (j / 2);
} else {
test = “–>”;
test = “–>” + (i / 2) + test + j;
}
System.out.println(test);
–j;
}
i++;
}
}
}

public class Q37 {
public static void main(String[] args) {
boolean var1=false, var2=false, var3=false, var4=false,var5=false;
boolean var6=false, result1=false, result2=false, result3=false, result4=false;
boolean result5=false, result6=false, result7=false, result8=false;
boolean result9=false, result10=false;
var1=(!true || true) && false;
var2=var1 && false;
var3=true && !false;
var4=false;
var5=true;
var6=var3 && false;
result1=(var1 && var2) && ( 40 % 3 > 45) || (var5 && var6);
result2=(var1 || var2) || (result1 && false);
result3=(var1 && result1) || result2 || var5;
result4=(var1 || var2) || ((var3 && var1) && false);
result5=(var1 && var2) && (result3 || var1);
result6=((var3 || !var2) && (result5)) || true;
result7=(var4 && result1) && ((result1 && false) || true);
result8=((var1 && result3) && (!var5 || var6)) && true;
result9=((result2 && var2) || (!result7 && var1)) && !false;
result10=!(var1 && true);
}
}

Show the values of the result variables in the above program:
result1
result2
result3
result4
result5
result6
result7
result8
result9
result10

public class Q38 {
public static void main(String[] args) {
int x = 0, p =0, sum = 0;
p = 1;
x = 2;
double q;
sum = 0;
while (p < 12) {
q = x + p-(sum+7/3)/3.0%2 ;
sum = sum + (x++) + (int)q;
System.out.println(sum);
if (x > 5)
p += 4/2;
else
p += 3%1;
}
sum = sum + p;
System.out.println(sum);
}
}

public class Q39 {
public static void main(String[] args) {
int test = 1;
int j = 0, k = 100;
while (k > 0) {
while (j < k ) {
test = k – j + 21;
System.out.println(1 + test / 2 +”11″);
j+=10;
}
k-=10;
}
}
}

public class Q40 {
public static void main(String[] args) {
String test = “”;
int i = 5, j = 0, k = 15;
while (i< 10) {
k-=1;
j = k;
while (j > 10 ) {
if (j % 2 == 0) {
test = “<–“;
test = test + i + 3 + “–>” + (j / 3);
} else {
test = “–>”;
test = “–>” + (i / 3) + test + j ;
}
System.out.println(test);
–j;
}
i++;
}
}
}

public class Q41 {
public static void main(String[] args) {
boolean var1=false, var2=false, var3=false, var4=false,var5=false;
boolean var6=false, result1=false, result2=false, result3=false, result4=false;
boolean result5=false, result6=false, result7=false, result8=false;
boolean result9=false, result10=false;
var1=(!false || false) && true;
var2=var1 && true;
var3=false && !true;
var4=true;
var5=false;
var6=var3 && true;
result1=(var1 && var2) && ( 40 % 3 > 45) || (var5 && var6);
result2=(var1 || var2) || (result1 && false);
result3=(var1 && result1) || result2 || var5;
result4=(var1 || var2) || ((var3 && var1) && false);
result5=(var1 && var2) && (result3 || var1);
result6=((var3 || !var2) && (result5)) || true;
result7=(var4 && result1) && ((result1 && false) || true);
result8=((var1 && result3) && (!var5 || var6)) && true;
result9=((result2 && var2) || (!result7 && var1)) && !false;
result10=!(var1 && true);
}
}

Show the values of the result variables in the above program:
result1
result2
result3
result4
result5
result6
result7
result8
result9
result10

public class Q42 {
public static void main(String[] args) {
String test = “”;
int i = 0, j = 0, k = 15;
test = “<–cat”;
while (i< 5){
k-=1;
j = k;
while (j > 10 ) {
if (j % 2 == 0) {
test += “–>”;
test = test + i + (j / 2);
} else {
test += “<–“;
test = test + (i / 2) + j;
}
System.out.println(test);
if (j == 12) {
test = “<–cat”;
}
–j;
}
i++;
}
}
}

public class Q43 {
public static void main(String[] args) {
String test = “”;
int i = 2, j = 0, k = 17;
test = “–>dog”;
while (i< 7) {
k-=1;
j = k;
while (j > 12 ) {
if (j % 2 == 0) {
test += “<–“;
test = test + i + (j / 2);
} else {
test += “–>”;
test = test + (i / 2) + j;
}
System.out.println(test);
if (j == 14) {
test = “–>dog”;
}
–j;
}
i++;
}
}
}

public class Q44 {
public static void main(String[] args) {
int x = 0, y =0;
int sum = 0;
double p;
while (x < 10) {
y = x / 2;
while (y < x) {
p = (x + 10.0) / 2;
sum = (sum % 2) + x – y * 2 + (int) p ;
System.out.println(sum);
y = y + 2;
}
if (x > 5) {
x++;
} else {
x += 2;
}
}
}
}

public class Q45 {
public static void main(String[] args) {
int x = 0, y =0;
int sum = 0;
double p;
while (x < 10) {
y = x / 2;
while (y < x) {
p = (x + 5.0) / 2;
sum = (sum % 2) + x – y * 2 + (int) p ;
System.out.println(sum);
y = y + 2;
}
if (x > 5) {
x++;
} else {
x += 2;
}
}
}
}

Reviews

There are no reviews yet.

Be the first to review “CSE110 – Trace the output of the following programs Solved”

Your email address will not be published. Required fields are marked *