Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. // declares an array of integers
  2.         int[] anArray;
  3.         int max;
  4.  
  5.         // allocates memory for 10 integers
  6.         anArray = new int[10];
  7.            
  8.         // initialize first element
  9.         anArray[0] = 100;
  10.         // initialize second element
  11.         anArray[1] = 200;
  12.         // and so forth
  13.         anArray[2] = 300;
  14.         anArray[3] = 400;
  15.         anArray[4] = 500;
  16.         anArray[5] = 600;
  17.         anArray[6] = 700;
  18.         anArray[7] = 800;
  19.         anArray[8] = 900;
  20.         anArray[9] = 1000;
  21.    
  22.     // postavi da je max odma prvi broj u polju
  23.     max = anArray[0];
  24.     for (int i = 0; i < anArray.length; i++) {
  25.       if (anArray[i] > max) {
  26.        max = anArray[i];
  27.       }
  28.     }
  29.    
  30.     System.out.println(max);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement