Advertisement
Shavit

P. 57 Ex. 5

Jan 25th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Treasure {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner(System.in);
  12.        
  13.         final int SIZE = 50;
  14.         int[] arr = new int[SIZE];
  15.         // array needs to be initialized with correct order.
  16.        
  17.         int next = 0;
  18.        
  19.         int current = in.nextInt();
  20.        
  21.         while(next != -1)
  22.         {
  23.             next = arr[current];
  24.             if(next == -1)
  25.                 break;
  26.             arr[next] = current;
  27.         }
  28.         System.out.print(current);
  29.        
  30.         in.close();
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement