0% found this document useful (0 votes)
2 views

predict the output

The document contains several code snippets demonstrating conditional statements and loops in Java. The outputs predict that 'y is greater', 'Odd and greater than 10', 'B is greater', followed by numbers 1 to 5, numbers 0 to 4, numbers 1 to 4, and numbers 1, 2, 4, 5 respectively. Each snippet illustrates different programming concepts such as if-else conditions, ternary operators, for loops, while loops, and control flow statements.

Uploaded by

thejas0716
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

predict the output

The document contains several code snippets demonstrating conditional statements and loops in Java. The outputs predict that 'y is greater', 'Odd and greater than 10', 'B is greater', followed by numbers 1 to 5, numbers 0 to 4, numbers 1 to 4, and numbers 1, 2, 4, 5 respectively. Each snippet illustrates different programming concepts such as if-else conditions, ternary operators, for loops, while loops, and control flow statements.

Uploaded by

thejas0716
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1 predict the output

a. int x = 10;

int y = 20;

if (x > y)

System.out.println("x is greater");

} else if (x == y) {

System.out.println("x is equal to y");

} else {

System.out.println("y is greater");

B int num = 15;

if (num > 10) {

if (num % 2 == 0) {

System.out.println("Even and greater than 10");

} else {

System.out.println("Odd and greater than 10");

} else {

System.out.println("Not greater than 10");

C int a = 5, b = 8;

String result = (a > b) ? "A is greater" : "B is greater";

System.out.println(result);

D for (int i = 1; i <= 5; i++) {

System.out.print(i + " ");

}
E int count = 0;

while (count < 5) {

System.out.print(count + " ");

count++;

F for (int i = 1; i < 10; i++) {

if (i == 5) {

break;

System.out.print(i + " ");

G for (int i = 1; i <= 5; i++) {

if (i == 3) {

continue;

System.out.print(i + " ");

You might also like