Advertisement
mmayoub

arrays-exercise 03, slide 28

Jul 1st, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. package class170629;
  2.  
  3. public class arrays03 {
  4.  
  5.     public static void main(String[] args) {
  6.         /*
  7.          * Exercise 3, slide 28
  8.          * input : none
  9.          * output: first 10 multiplications of
  10.          * 3 (from an array)
  11.          */
  12.  
  13.         // define an integer array, size=10
  14.         int[] numbers = new int[10];
  15.  
  16.         // scan the array
  17.         for (int i = 0; i < numbers.length; i += 1) {
  18.             // in position i store the number 3*i
  19.             numbers[i] = 3 * i;
  20.  
  21.             // print numbers from the array
  22.             System.out.printf("%d ", numbers[i]);
  23.         }
  24.         System.out.println();
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement