Question: boolean flag = true; String message = Hello, Java; System.out.println ( Integer: + num ) ; System.out.println ( Double: + decimal

boolean flag = true;
String message = "Hello, Java";
System.out.println("Integer: "+ num);
System.out.println("Double: "+ decimal);
System.out.println("Character: "+ letter);
System.out.println("Boolean: "+ flag);
System.out.println("String: "+ message);
}
}
Consider the following code fragment. Explain the purpose of each control structure
and describe the expected output. Complete the code by adding a loop that prints
numbers from 1 to 5.(7 marks)
public class ControlStructuresExample {
public static void main(String| args){
int x =5;
// If-else statement
if (x>0){
System.out.println("x is positive");
} else {
System.out.println("x is not positive");
}
// For loop
for (int i=0; i<5; i++){
System.out.println("i: "+ i);
}
// While loop
int y =3;
while (y>0){
System.out.println("y: "+ y);
y--;
}
// Add a loop here to print numbers from 1 to 5
}
}2. Consider the following code fragment. Explain the purpose of each control structure and describe the expected output. Complete the code by adding a loop that prints numbers from 1 to 5.(7 marks)
public class ControlStructures Example {
public static void main(String[] args){
int x =5
// If-else statement
if (x >0) System.out.println("x is positive");
} else { System.out.println("x is not positive");
// For loop
for (int i <5 ;i++)\ i =0 System.out.println("i: "+ i);
// While loop int y =3i while (y >0) System.out.println("y: "+ y); :
// Add a loop here to print numbers from 1 to 5
1
<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!