Hi guys, my program im working on ends when it shouldnt.....
here's the main method.
public static void main(String[] args)
{
String answer;
do
{
boolean whole=false;
boolean whole2=false;
Scanner sc = new Scanner(System.in);
int one=0, two=0;
do
{
try{
System.out.print("Enter the first whole number: ");
one = sc.nextInt();
whole = true;
}
catch(Exception e)
{
System.out.println("You did not enter a whole number.");
}
}while(whole=false);
do
{
try{
System.out.print("Enter the second whole number: ");
two = sc.nextInt();
whole2=true;
}
catch(Exception e)
{
System.out.println("You did not enter a whole number.");
}
}while(whole2=false);
System.out.println("Results from adding: " + add(one,two));
System.out.println("Results from subtracting: " + sub(one,two));
System.out.println("Results from multiplying: " + mult(one,two));
System.out.println("Results from dividing: " + div(one,two));
System.out.println("Results from modulus: " + mod(one,two));
System.out.println("Results from Math.pow: " + pow(one,two) + "\n\n");
System.out.println("Do you wish to enter two more numbers? y/n: ");
answer = sc.nextLine();
}while(answer.equalsIgnoreCase("y"));
}
if you notice nearly the entire method is in a do while loop..... Now what happens is, i execute the program i enter the two numbers, it does all the correct method calling and prints everything out correctly.... now the last line asks the user if they want to enter in another two numbers.... but what happens is my program displays that line and doesnt give the user a chance to enter "y" or "n"..... it just stops.... i tried making
String answer = "y";
at the beginning of the method but the do while loop still doesnt repeat.... any ideas?