import java.util.*;
public class RandomAddArray {
public static void main (String[] args) {
AddArray ad = new AddArray();
int[] Ar = new int[4];
ad.AddArray(Ar);
}
}
class AddArray {
public void AddArray(int a[]) {
for(int i = 0; i < a.length; i++) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
a[i] = n + 2;
System.out.print(a[i]);
}
}
}
In my code I read four integers from the console and add 2
to each of them.
If I type number 1
four times, System.out.print
should output 3
four times.
However, I get the following output: