Which statement correctly prints an integer variable named `x` in Java?
A
System.out.println(x); B
print(x); C
echo(x); D
console.log(x);
Analysis & Theory
Java uses `System.out.println(x);` to print variables.
What will be the output?
int x = 5;
System.out.println("x = " + x);
A
x = x B
x = 5 C
"x = " + x D
5 = x
Analysis & Theory
The string "x = " is concatenated with the value of `x`, which is 5.
How can you print multiple variables `a` and `b` in the same line?
A
System.out.print(a b); B
System.out.print(a, b); C
System.out.println(a + " " + b); D
print(a + b);
Analysis & Theory
You can concatenate variables using `+` and add spaces using `" "`.
Which is the correct way to print a `char` variable in Java?
A
System.print(c); B
System.out.print(c); C
System.out.char(c); D
System.out.printlnChar(c);
Analysis & Theory
`System.out.print(c);` is correct for printing any variable, including `char`.
What will this code print?
String name = "Alex";
System.out.println("Hello, " + name);
A
Hello, Alex B
Hello, name C
Alex Hello D
Error
Analysis & Theory
String concatenation combines the literal and variable, resulting in `Hello, Alex`.
What will be printed?
int x = 2, y = 3;
System.out.println(x + y);
A
x + y B
5 C
23 D
Error
Analysis & Theory
`x + y` is integer addition: 2 + 3 = 5.
What does `System.out.println()` do after printing?
A
Deletes the variable B
Moves to a new line C
Stops the program D
Repeats the value
Analysis & Theory
`println` prints and moves the cursor to the next line.
Which method would you use to print without a newline?
A
System.print() B
System.out.write() C
System.out.print() D
System.out.println()
Analysis & Theory
`System.out.print()` prints on the same line.
How do you print both a string and an integer?
int age = 20;
A
System.out.println("Age is" age); B
System.out.println("Age is" + age); C
System.out.println("Age is: age"); D
System.out.println(age "is your age");
Analysis & Theory
Use `+` to concatenate string and variable: `"Age is" + age`.
Which of the following prints a boolean value correctly?
boolean isJavaFun = true;
A
System.out.println("isJavaFun"); B
System.out.println(isJavaFun); C
System.out.println("true"); D
System.out.println('isJavaFun');
Analysis & Theory
`System.out.println(isJavaFun);` will output `true` because it prints the value of the variable.