Assignment Answer
Assignment Answer
Assignment No. 3
// if statement
if (num > 0) {
System.out.println("Positive number");
}
// switch statement
switch (num) {
case 10:
System.out.println("Number is 10");
break;
default:
System.out.println("Number is not 10");
}
// for loop
for (int i = 1; i <= 5; i++) {
System.out.println("For loop iteration: " + i);
}
// while loop
int i = 1;
while (i <= 5) {
System.out.println("While loop iteration: " + i);
i++;
}
// do-while loop
int j = 1;
do {
System.out.println("Do-while loop iteration: " + j);
j++;
} while (j <= 5);
}
}