dm6801

20171116 - 04 - classEx_05

Nov 16th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         Scanner s = new Scanner(System.in);
  3.        
  4.         //init array
  5.         int[] arr = new int[10];
  6.        
  7.         //populate array
  8.         System.out.printf("Type in %d Integers: ", arr.length);
  9.         for (int i=0; i<arr.length; i+=1) {
  10.             arr[i] = s.nextInt();
  11.            
  12.         }
  13.        
  14.         //this is where the magic happens
  15.         for (int i=0; i<arr.length; i+=1) {
  16.             if (i%2==0) { arr[i] += 1; }
  17.             if (i%3==0) { arr[i] -= 1; }
  18.         }
  19.        
  20.         //print out modified array
  21.         for (int n: arr) {
  22.             System.out.printf("%d ", n);
  23.         }
  24.        
  25.         s.close();
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment