Advertisement
oona

rainfall data

Jan 20th, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1.  
  2. public class rainfallData {
  3.  
  4.     public static void main(String[] args) {
  5.         // TODO Auto-generated method stub
  6.        
  7.         //inputs
  8.         double calledrainfall[] = {1.0, 1.5, 2.3, 3.1, 1.6, 2.8, 3.0, 1.7, 2.5, 4.0};
  9.         String date[] = {"6th January", "13th January", "20th January", "27th January", "3rd February", "10th February", "17th February", "24th February", "4th March", "11th March"};
  10.         double temp1;
  11.         String temp2;
  12.        
  13.     for(int i=0; i<calledrainfall.length; i++)
  14.     {
  15.         for(int j=1; j<(calledrainfall.length-i); j++)
  16.         {
  17.             if(calledrainfall[j-1]<calledrainfall[j])
  18.             {
  19.                 temp1 = calledrainfall[j-1];
  20.                 calledrainfall[j-1] = calledrainfall[j];
  21.                 calledrainfall[j] = temp1;
  22.                
  23.                 temp2 = date[j-1];
  24.                 date [j-1] = date[j];
  25.                 date [j] = temp2;
  26.             }
  27.         }
  28.     }
  29.  
  30.     for(int i=0; i<date.length; i++)
  31.        
  32.         System.out.println("The highest rainfall was " + calledrainfall[i] + " cm on " + date[i]);
  33.  
  34.     }//class ends
  35.  
  36. }//program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement