0
0
Javaprogramming~10 mins

Why input and output are required in Java - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print a message to the console.

Java
System.out.[1]("Hello, world!");
Drag options to blanks, or click blank then click option'
Aoutput
Bprint
Cprintln
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'print' which does not add a new line.
Trying to use methods that don't exist like 'write' or 'output'.
2fill in blank
medium

Complete the code to read a line of input from the user.

Java
Scanner scanner = new Scanner(System.in);
String input = scanner.[1]();
Drag options to blanks, or click blank then click option'
AnextLine
BinputLine
CreadLine
DnextInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nextInt' which reads only integers.
Trying to use 'readLine' which is not a Scanner method.
3fill in blank
hard

Fix the error in the code to correctly read an integer input.

Java
Scanner scanner = new Scanner(System.in);
int number = scanner.[1]();
Drag options to blanks, or click blank then click option'
AreadInt
BinputInt
CnextLine
DnextInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nextLine' which reads a string, not an integer.
Using non-existent methods like 'readInt' or 'inputInt'.
4fill in blank
hard

Fill both blanks to create a program that reads a name and prints a greeting.

Java
Scanner scanner = new Scanner(System.in);
String name = scanner.[1]();
System.out.[2]("Hello, " + name + "!");
Drag options to blanks, or click blank then click option'
AnextLine
Bprintln
CnextInt
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using nextInt() to read a name.
Using print() instead of println().
5fill in blank
hard

Fill all three blanks to read two numbers and print their sum.

Java
Scanner scanner = new Scanner(System.in);
int num1 = scanner.[1]();
int num2 = scanner.[2]();
System.out.[3]("Sum: " + (num1 + num2));
Drag options to blanks, or click blank then click option'
AnextLine
BnextInt
Cprintln
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using nextLine() to read integers.
Using print() instead of println().