Advertisement
Glampkoo

My first java (working) program

Jul 14th, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 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.         //I could just use chars instead of string. I don't know if it has any difference at all.
  10.         String y = "Y";
  11.         String n = "N";
  12.         while (t < 10 & y.equalsIgnoreCase("y")){
  13.             System.out.print("The number is: ");
  14.             System.out.println(t + ". Continue? y/n");
  15.             y = userInput.nextLine();
  16.             t++;
  17.         }
  18.         if (t == 10){
  19.             System.out.println("It got to 10.");
  20.         }
  21.         if (n.equalsIgnoreCase("n") & t != 10){
  22.             System.out.println("You decided to not continue.");
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement