Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JollyJumpers.java
- // Author: Jeffrey Cartagena
- import java.io.*;
- import java.util.*;
- public class JollyJumpers {
- public static void main(String[] args)throws IOException {
- try{
- Scanner inFile = new Scanner(new FileReader("data.in"));
- PrintWriter outFile = new PrintWriter(new FileWriter("data.out"));
- int qty;
- int[] numbers;
- int[] results;
- while(inFile.hasNextInt())
- {
- qty = inFile.nextInt();
- numbers = new int[qty];
- results = new int [qty-1];
- for(int i=0; i < qty; i++)
- numbers[i] = inFile.nextInt();
- for(int i=0; i < qty-1; i++)
- results[i] = Math.abs(numbers[i] - numbers[i+1]);
- boolean jolly = true;
- for(int i=0; i < qty-2; i++)
- {
- if(Math.abs(results[i]-results[i+1]) != 1)
- {
- jolly = false;
- break;
- }
- }
- if(jolly)
- outFile.println("Jolly");
- else
- outFile.println("Not Jolly");
- }
- System.out.println("Finishing the program");
- System.in.read();
- inFile.close();
- outFile.close();
- }
- catch(IOException ex){
- System.out.println("Input file doesn't exist");
- System.in.read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement