Task: Create an array of all even numbers from 2 to 20 and output the array elements to the screen first on a line, separating one element from another by a space, and then in a column (separating one element from another by the beginning of a new line). Before creating an array, consider what size it will be.
My code is:
public class Task1 { public static void main(String[] args) { int[] mas1 = new int[9]; for (int i = 2; i <= 20; i = i + 2) { System.out.print(i + " "); if (i == 20) { System.out.println(i); System.out.println(); } } for (int i = 2; i <= 20; i = i + 2) { System.out.println(i); } } } According to the results, 2 numbers “20” are displayed in the string (everything is in order with the bar). If in the first for I change the condition to i < 20 , it turns out to be nonsense.
What am I doing wrong?