Advertisement
Adumb_Copper

Intro to Arrays Part 3

Nov 16th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. class TwoLargest
  2. {
  3.     public static void main ( String[] args )  
  4.     {
  5.         int[] data = {3, 1, 5, 7, 4, 12, -3, 8, -2};
  6.        
  7.         // compute the two largest-Note: data.length returns
  8.         // an integer value, the number of elements in the array
  9.        
  10.         int schmorp = -999999999;
  11.         int florp = 0;
  12.         int filler;
  13.        
  14.         for ( int index = 0; index < data.length; index++)
  15.         {
  16.             int glorp = data[index];
  17.            
  18.             if (glorp >= schmorp) {
  19.                 florp = schmorp;
  20.                 schmorp = glorp;
  21.             } else {
  22.                 filler = 0;
  23.             }
  24.                
  25.  
  26.         }
  27.  
  28.         // write out the two largest values
  29.         System.out.println("largest values: " + schmorp + " " + florp);
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement