Advertisement
Guest User

Untitled

a guest
May 10th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.     public static int[] shop(int[] shoplist, int credit)
  2.     {  
  3.         boolean found = false;
  4.         int i = 0;
  5.         System.out.println("Your credit is: " + credit);
  6.         while(!found)
  7.         {
  8.             int j = i + 1;
  9.             while ( j != shoplist.length)
  10.             {
  11.                 if(shoplist[i] + shoplist[j] == credit)
  12.                 {
  13.                     int[] shopped = new int[2];
  14.                     shopped[0] = i;
  15.                     shopped[1] = j;
  16.                     System.out.println("You bought " + (i+1) + " and " + (j+1));
  17.                     System.out.println("With values" + shoplist[i] + " and " + shoplist[j]);
  18.                     return shopped;
  19.                 }
  20.                 j++;
  21.             }
  22.             i++;
  23.         }
  24.         return null;
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement