0
0
Javaprogramming~20 mins

Output using System.out.print in Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Java Print Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Java code snippet?
Consider the following Java code. What will it print to the console?
Java
public class Main {
    public static void main(String[] args) {
        System.out.print("Hello");
        System.out.print(" ");
        System.out.print("World");
    }
}
AHello World
BHello\nWorld
CHelloWorld\n
DHello World\n
Attempts:
2 left
💡 Hint
System.out.print does not add a new line after printing.
Predict Output
intermediate
2:00remaining
What does this Java code print?
Look at this code. What is the exact output?
Java
public class Main {
    public static void main(String[] args) {
        System.out.print(5 + 3);
        System.out.print("+");
        System.out.print(2);
    }
}
A5+32
B8+2
C532
D10
Attempts:
2 left
💡 Hint
Remember that + between numbers adds, but + between strings concatenates.
Predict Output
advanced
2:00remaining
What is the output of this Java code with mixed print and println?
What will this code print exactly?
Java
public class Main {
    public static void main(String[] args) {
        System.out.print("Start");
        System.out.println("Middle");
        System.out.print("End");
    }
}
AStartMiddleEnd
BStart\nMiddleEnd
CStartMiddle\nEnd
DStart\nMiddle\nEnd
Attempts:
2 left
💡 Hint
System.out.println adds a new line after printing, System.out.print does not.
Predict Output
advanced
2:00remaining
What is the output of this Java code with character and string prints?
What does this code print?
Java
public class Main {
    public static void main(String[] args) {
        System.out.print('A');
        System.out.print("B");
        System.out.print(67);
    }
}
A65B67
BABC
CABC67
DAB67
Attempts:
2 left
💡 Hint
Single quotes print the character, numbers print the number itself.
Predict Output
expert
2:00remaining
What is the output of this Java code with expressions inside print?
What will this code print exactly?
Java
public class Main {
    public static void main(String[] args) {
        System.out.print("Result: " + 2 + 3);
        System.out.print(" and " + (2 + 3));
    }
}
AResult: 23 and 5
BResult: 5 and 5
CResult: 23 and 23
DResult: 5 and 23
Attempts:
2 left
💡 Hint
String concatenation happens left to right, parentheses change order of operations.