Hi, can anyone see where Im going wrong here? It all seems to work fine until it gets to the bottom where the user is asked if they would like to input another number (y) or (n). When (y) is selected it just keeps asking if they would like to input another number and doesn't go back around the loop!!! or it is going back around the loop, but bypassing the main part. import java.util.Scanner; //This program asks the user to input a number between 1 to 200, then adds all //numbers upto number input and outputs the total. class program5 { public static void main(String[]args) { Scanner input = new Scanner(System.in); int number=0, x=0, count=1, result, total=0, num=0; String answer=("y"); while (answer.equalsIgnoreCase("y")) { while (!(number>0 && number<=200)) { System.out.println("Please input a number between 1-200."); number = input.nextInt(); if (number>0 && number<=200) { for (x=1; x<=number; x++) { total=total + x; if (!(x ==number)) { System.out.print(x +" + "); } else { System.out.println(x + " = "+total); } } } else System.out.println("\nSorry, that number is out of range."); System.out.println("---------------------------------------"); } System.out.println("Would you like to enter another number? Yes (y) or No (n)."); answer = input.next(); } System.out.println("Thank you, hope to see you again soon."); } Code (markup):
Have you tried something like this? if (answer.equalsIgnoreCase("n")) { System.out.println("Thank you, hope to see you again soon."); } Code (markup): Also have you made sure the input works correctly? Print answer on screen to verify it actually works.