Spaces:
Running
Running
| The program initializes the integer variable maximum with a random initial value. | |
| Your task is to print the numbers from one to the maximum and back from the maximum to one, all underlined. Each number is printed on its own line. | |
| For example, if the value of the maximum were 4, the program should print the numbers | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 3 | |
| 2 | |
| 1 | |
| import java.util.Random; | |
| public class Test{ | |
| public static void main(String[] args){ | |
| final Random r = new Random(); | |
| int maximum = r.nextInt(15) + 5; | |
| System.out.println("maximum == " + maximum); | |
| for (int i=1; i<=maximum; i++) { | |
| System.out.println(i); | |
| } | |
| for (int i=maximum-1; i>0; i--) { | |
| System.out.println(i); | |
| } | |
| } | |
| } | |
| maximum == 19 | |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 18 | |
| 17 | |
| 16 | |
| 15 | |
| 14 | |
| 13 | |
| 12 | |
| 11 | |
| 10 | |
| 9 | |
| 8 | |
| 7 | |
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 1 | |