Advertisement
Guest User

Blackone

a guest
Nov 17th, 2009
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. // JollyJumpers.java
  2. // Author: Jeffrey Cartagena
  3.  
  4. import java.io.*;
  5. import java.util.*;
  6.  
  7. public class JollyJumpers {
  8.    
  9.     public static void main(String[] args)throws IOException {
  10.         try{
  11.             Scanner inFile = new Scanner(new FileReader("data.in"));
  12.             PrintWriter outFile = new PrintWriter(new FileWriter("data.out"));
  13.             int qty;
  14.             int[] numbers;
  15.             int[] results;
  16.            
  17.             while(inFile.hasNextInt())
  18.             {
  19.                 qty = inFile.nextInt();
  20.                 numbers = new int[qty];
  21.                 results = new int [qty-1];
  22.                
  23.                 for(int i=0; i < qty; i++)
  24.                     numbers[i] = inFile.nextInt();
  25.                
  26.                 for(int i=0; i < qty-1; i++)
  27.                     results[i] = Math.abs(numbers[i] - numbers[i+1]);
  28.                
  29.                 boolean jolly = true;
  30.                 for(int i=0; i < qty-2; i++)
  31.                 {
  32.                     if(Math.abs(results[i]-results[i+1]) != 1)
  33.                     {
  34.                         jolly = false;
  35.                         break;
  36.                     }
  37.                 }
  38.                
  39.                 if(jolly)
  40.                     outFile.println("Jolly");
  41.                 else
  42.                     outFile.println("Not Jolly");
  43.                
  44.             }
  45.            
  46.             System.out.println("Finishing the program");
  47.             System.in.read();
  48.            
  49.             inFile.close();
  50.             outFile.close();
  51.            
  52.         }
  53.        
  54.         catch(IOException ex){
  55.             System.out.println("Input file doesn't exist");
  56.             System.in.read();          
  57.         }
  58.  
  59.     }
  60.  
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement