Advertisement
Glampkoo

Problems with strings

Jul 16th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test {
  4.         static Scanner userInput = new Scanner(System.in);
  5.        
  6.         public static void main(String[] args){
  7.                 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.");
  8.                 int t = 1;
  9.                 String y = "Y";
  10.                 String n = "N";
  11.                 while (t < 10 & y.equalsIgnoreCase("y")){
  12.                         System.out.print("The number is: ");
  13.                         System.out.println(t + ". Continue? y/n");
  14.                         y = userInput.nextLine();
  15.                         t++;
  16.                         if (userInput != y & n != "n"){
  17.                             System.out.println("Please insert a valid answer.");
  18.                         }
  19.                     }
  20.            
  21.                 if (t == 10){
  22.                     System.out.println("It got to 10.");
  23.                 }
  24.            
  25.                 if (n.equalsIgnoreCase("n") & t != 10){
  26.                     System.out.println("You decided to not continue.");
  27.                 }
  28.         }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement