Show the output of the following code: In java (write the output for each printl
ID: 3828649 • Letter: S
Question
Show the output of the following code: In java (write the output for each println statement if the println statement is executed in the program).
public class Test {
public static void main(String[] args) {
System.out.println((int)(Math.random()));
System.out.println(Math.pow(2, 3));
System.out.println(34 % 7);
System.out.println(3 + 4 * 2 > 2 * 9);
int number = 4;
if (number % 3 == 0)
System.out.println(3 * number);
System.out.println(4 * number);
int x = 943;
System.out.println(x / 100);
System.out.println(x % 100);
if (x%2 == 0)
System.out.println(x + “ is “ + “even”);
else
System.out.println(x + “ is “ + “odd”);
int y = -1;
y++;
System.out.println(y);
}
}
Explanation / Answer
public class Test {
public static void main(String[] args) {
System.out.println((int)(Math.random())); // 0
System.out.println(Math.pow(2, 3)); // 8.0
System.out.println(34 % 7); // 6
System.out.println(3 + 4 * 2 > 2 * 9); // false
int number = 4;
if (number % 3 == 0)
System.out.println(3 * number); // not executed
System.out.println(4 * number); // 16
int x = 943;
System.out.println(x / 100); //9
System.out.println(x % 100); // 43
if (x%2 == 0)
System.out.println(x + " is " + "even"); // 943 is odd
else
System.out.println(x + " is " + "odd"); // not executed
int y = -1;
y++;
System.out.println(y); // 0
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.