What code produces the intended output below?
Ready
Set
Go!
System.out.print("Ready\nSet\nGo!\n");
Which of the following is a valid identifier in Java?
123java
main
java1234
{abce
)whoot
java1234
What will be printed by the following code?
int x = 10;
int y = 20;
System.out.print( x / y - 20);
-20
What is printed when the code segment has been executed?
int z = 5;
z = z % 1;
z += 5;
z = z / z;
z /= z;
System.out.println(z);
1
What is printed as a result of executing the code segment?
double p = 5.6;
double n = 1.2;
System.out.print((int) (p + 0.5));
System.out.print((int) (n - 0.5));
60
What is printed as a result of executing the code segment?
System.out.println("A");
System.out.println("B");
System.out.print("C");
System.out.print("D");
A
B
CD
Which of the following is a GOOD identifier name
java1234
grade
student_grade
studentGrade
studentGrade
Which of the following can be used as a replacement for /* missing expression */ so that the code segment prints 31 ?
int x, y;
x = 3;
y = /* missing expression */;
x = 1 + 2 * y;
System.out.print(x);
System.out.println(y);
What is printed when the code segment has been executed?
int z = 0;
z++;
z *= 2;
z = z + z;
z -= 10;
System.out.println(z);
-2
What is printed as a result of executing the code segment?
double a = 11;
int b = (int) (a / 2);
double c = (double) b / 2;
System.out.print(b);
System.out.print(" ");
System.out.print(c);
5 2.5
What is printed as a result of executing the code segment?
System.out.print("Hello!");
System.out.println("How ");
System.out.print("are ");
System.out.print("you?");
Hello!How
are you?
Suppose you were developing a fitness tracker. Which of the following would be a variable your program may use?
int stepsTaken
double stepsTaken
float stepsTaken
boolean stepsTaken
int stepsTaken
What will be printed by the following code?
int x = 10;
int y = 20;
System.out.print( x / (y - 20) );
ArithmeticException or divide by zero syntax error
What is printed when the code segment has been executed?
int z = 0;
z++;
z += z;
z = z + 1;
z -= -1;
System.out.println(z);
4
What is printed as a result of executing the code segment?
double d = 0.25;
int i = 3;
double diff = d - i;
System.out.print((int)diff + 0.5);
-1.5
What is printed as a result of executing the code segment?
System.out.print("I");
System.out.println(" am ");
System.out.println("a ");
System.out.print("troll!");
I am
a
troll!
What is the appropriate data type for a variable containing the value of the expression
/* data type */ isWeird = 10 < 25;
boolean
What do the following arithmetic expressions evaluate to?
4 / 5 % 3
4 / (7 % 4)
4 - 1 / 2 - 2
0
1
2
What is printed when the code segment has been executed?
int z = 0;
z--;
z *= 2
z += 1;
z = z + 1;
z -= -1;
System.out.println(z);
-1
What does the code segment below print?
int num1 = 5;
int num2 = 10;
double ans = num1 / num2;
System.out.print(ans);
0
What is printed as a result of executing the code segment?
System.out.print("Is ");
System.out.print('this");
system.out.print(" real");
System.out.print("life");
Nothing, due to a syntax error
George Boole
What is the value of x?
int a = 4;
int b = 3;
int c = 2;
int d = 1;
double x = a + b * c % d;
4.0
What is printed when the code segment has been executed?
int z = 15;
z /= 10;
z += z;
z --;
z %= 4;
System.out.println(z);
1
Consider the following code segment, which is intended to display 6.0. How would you fix it?
double fact1 = 1 / 2;
double fact2 = 3 * 4;
double product = fact1 * fact2;
System.out.println(product);
double fact1 = 1.0/2;
or
double fact1 = 1/2.0;
or
double fact1 = (double)1 / 2;