Advertisement
oona

skyhigh airlines

Feb 4th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. public class skyHigh {
  2.  
  3.     public static void main(String[] args) {
  4.         // TODO Auto-generated method stub
  5.        
  6.         //inputs
  7.         String flightNumber[] = {"AF 1975", "AY 2003", "TG 1999", "SQ 1010", "PF 2606", "DY 2009", "JL 1996", "US 1950", "BA 2505", "LH 1998"};
  8.         int departureTime[] = {1710, 1432, 1500, 1807, 1515, 1948, 1426, 1518, 1841, 1400};
  9.         String temp1;
  10.         int temp2;
  11.        
  12.         //classify the flights by departure
  13.         for(int i=0; i<departureTime.length; i++)
  14.         {
  15.             for(int j=1; j<(departureTime.length-i); j++)
  16.             {
  17.                 if(departureTime[j-1]<departureTime[j])
  18.                 {
  19.                     temp1 = flightNumber[j-1];
  20.                     flightNumber [j-1] = flightNumber[j];
  21.                     flightNumber[j] = temp1;
  22.                    
  23.                     temp2 = departureTime[j-1];
  24.                     departureTime[j-1] = departureTime[j];
  25.                     departureTime[j] = temp2;
  26.                 }
  27.             }
  28.         }
  29.         for(int i=0; i<departureTime.length; i++)
  30.            
  31.             System.out.println("Your flight is " + flightNumber[i] + " departing at " + departureTime[i]); //the number of flights and their departures
  32.             //in ascending order
  33.        
  34.  
  35.     }//class ends
  36.  
  37. }//program ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement