I want my program to keep asking the user to enter the numerator and if the input was a number it asks for the denominator it checks if it is 0 or not if 0 it shows error message and if not it completes division
but if the numerator was a string it sends an error message but if it is E or e it exits the program
but the problem is that it asks me to enter the numerator twice and it doesn't ask me to enter the denominator and it devises the first number I enter over the second even if I enter a string it asks me to enter the string twice
package Division;
import java.util.Scanner;
public class Division{
public static void main(String[] args) {
Object n,d;
Scanner input = new Scanner(System.in);
do{
System.out.println("Enter the numerator: ");
n = input.next();
System.out.println("");
if(input.hasNextDouble())
{
System.out.println("Enter the denominator: ");
d = input.nextDouble();
if (d==0){
System.out.println("You can't divide "+n+" by 0");
}
else{
System.out.println(n+"/"+d+" is"+Double.valueOf((String) n)/Double.valueOf((double) d));
}
}
else if(input.hasNextLine()) {
if(n.equals("e")||n.equals("E")){
System.out.println("Good Bye");
}
else{
System.out.println("You entered bad data. Please try again.");
}
}
}while(n.equals("e")==false||n!=n.equals("E")==false);
}
}