Hey guys,
Just made a small new program off one I made earlier, it asks you for a sequence and then classifies it to be either arithmetic or geometric or nothing. Here is the code:
import java.util.Scanner; public class ArithmeticSequenceClassification { public static void main(String[] args) { int[] sequence = new int[4]; int num1, num2, num3, num4, num5; int d; int n; boolean isArithmetic, isGeometric, isNothing; String output; Scanner scan = new Scanner(System.in); System.out.println("Please enter 5 numbers. Your inputs will be scanned and classified by their sequence attributes."); System.out.print("Enter your first number: "); num1 = scan.nextInt(); System.out.print("Enter your second number: "); num2 = scan.nextInt(); System.out.print("Enter your third number: "); num3 = scan.nextInt(); System.out.print("Enter your fourth number: "); num4 = scan.nextInt(); System.out.print("Enter your last number: "); num5 = scan.nextInt(); sequence[0] = num1; sequence[1] = num2; sequence[2] = num3; sequence[3] = num4; sequence[4] = num5; d = num2 - num1; n = num2 * num3; if(num2 - num1 == d) { if(num3 - num2 == d) { if(num4 - num3 == d) { if(num5 - num4 == d) { isArithmetic = true; isGeometric = false; isNothing = false; } } } } else if(num2 / num1 == n && num2 % num1 == 0) { if(num3 / num2 == n && num3 % num2 == 0) { if(num4 / num3 == n && num4 % num3 == 0) { if(num5 / num4 == n && num5 % num4 == 0) { isGeometric = true; isArithmetic = false; isNothing = false; } } } } else { isArithmetic = false; isGeometric = false; isNothing = true; } if(isArithmetic = true) { output = "Your sequence was: Arithmetic."; } else if(isGeometric = true) { output = "Your sequence was: Geometric."; } else { output = "Your sequence was not a sequence."; } System.out.print(output); } }
I cannot see any possible errors within the program, and neither does Eclipse. However, when I run it, it will not accept my number inputs and go on to asking for the next number!
Help please?
-Silent