1. public static void main(String[] args) { int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for(int i=0; i<numbers.length-1; i++) { System.out.print(numbers[i]+ " "); } System.out.println(); } //output: 1 2 3 4 5 6 7 8 9 2. public static void main(String[] args) { int[] numbers = {10,9,8,7,6,5,4,3,2,1}; for(int i=0; i<numbers.length-1; i++) { if(numbers[i] > numbers[i+1]) { numbers[i+1] = numbers[i+1] * 2; System.out.print(numbers[i+1]+ " "); } } System.out.println(); } //output: 18 16 14 12 10 8 6 4 2
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter