The program below print numbers on the screen using Java. It is the solution to Deitel’s Java How to Program (9th Edition) Chapter 2 Exercise 2.14.
Question: 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:
- one System.out.println statement.
- four System.out.print statements.
- one System.out.printf statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class DisplayNumbersOneToFour { public static void main (String [] args) { System.out.println ("\nThis Application Displays The Numbers 1 To 4 Using " + "The System.out.println, System.out.print And System.out.prinf" + " Methods"); System.out.println (); System.out.println ("1 2 3 4"); System.out.print ("1 "); System.out.print ("2 "); System.out.print ("3 "); System.out.print ("4\n"); System.out.printf ("%d %d %d %d", 1,2,3,4); } } |
1 Comment
I read a lot of stuff and I found that the writing clarifying that exactly want to say was very good so I am impressed and I will like to come again in future..