Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Test {
- static Scanner userInput = new Scanner(System.in);
- public static void main(String[] args){
- System.out.println("Until the number hits 10, you can choose yes or no. If you choose yes, it will continue, if no, it will stop.");
- int t = 1;
- String y = "Y";
- String n = "N";
- while (t < 10 & y.equalsIgnoreCase("y")){
- System.out.print("The number is: ");
- System.out.println(t + ". Continue? y/n");
- y = userInput.nextLine();
- t++;
- if (userInput != y & n != "n"){
- System.out.println("Please insert a valid answer.");
- }
- }
- if (t == 10){
- System.out.println("It got to 10.");
- }
- if (n.equalsIgnoreCase("n") & t != 10){
- System.out.println("You decided to not continue.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement