I am trying to complete a assignment from a online Java Tutorial and I am currently on a question regarding While Loops. This is my code:
import java.util.Scanner;
public class bird {
public static void main(String[] args){
Scanner bucky = new Scanner(System.in);
final String end = "END";
String bird;
int amount;
System.out.println("What bird did you see in your garden? ");
bird = bucky.nextLine();
while(!(bird.equals(end))){
System.out.println("How many were in your garden? ");
amount = bucky.nextInt();
}
}
}
My problem is the code is meant to terminate if END is inputted by the user so it needs to be outside the While Loop. But without it being inside the loop, it doesn't repeat the question for more types of birds. Is there a way to have the first "What bird did you see? " inside the loop whilst also having a condition that exits the loop if the Ending condition is met?