Advertisement
oona

names and phone numbers

Jan 20th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1.  
  2. public class namesAndNumbers {
  3.  
  4.     public static void main(String[] args) {
  5.         // TODO Auto-generated method stub
  6.        
  7.         //inputs
  8.         String names[] = {"Stanley Tucci", "Rosie Wild", "Jim Parsons", "Violet Canes", "Sterling Sunk", "Britt Ekland", "Robert Cool", "Kate Coquil", "George Long", "Dyan Cannon"};
  9.         String phoneNumbers[] = {"1912 2814", "6575 9988", "7598 1234", "8790 0011", "0404 6482", "2034 1942", "1996 0002", "1998 4001", "1111 4578", "1978 0008"};
  10.        
  11.         String temp;
  12.        
  13.         for(int i=0; i<names.length; i++)
  14.         {
  15.             for(int j=1; j<names.length-i;j++)
  16.             {
  17.                 if(names[j-1].compareTo(names[j])>0)
  18.                 {
  19.                    
  20.                     temp = names[j-1];
  21.                     names[j-1] = names[j];
  22.                     names[j] = temp;
  23.                    
  24.                    
  25.                     temp = phoneNumbers[j-1];
  26.                     phoneNumbers[j-1] = phoneNumbers[j];
  27.                     phoneNumbers[j] = temp;
  28.                 }
  29.                
  30.                
  31.             }
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement