30.7k views
4 votes
Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space.Use the following techniques: a) Use one System.out.println statement. b) Use four System.out.print statements. c) Use one System.out.printf statement

1 Answer

5 votes

Answer:

A. System.out.println("1 2 3 4");

B. System.out.print("1 ");

System.out.print("2 ");

System.out.print("3 ");

System.out.print("4");

C. System.out.printf("%d %d %d %d", 1, 2, 3, 4);

Step-by-step explanation:

All of these techniques will produce the same output of "1 2 3 4" on the same line, with each pair of adjacent numbers separated by one space.

User Adam Spicer
by
7.6k points