Advertisement
fosterbl

WhileLoop3.java

Oct 8th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. /*
  2. Tell the user the riddle/joke "Pete and Repeat were fishing and Pete fell off the boat. Who was left?" and ask for the answer. Tell the riddle/joke repeatedly while they input Repeat until they enter Stop.
  3. Example: Pete and Repeat were fishing and Pete fell off the boat. Who was left?
  4.         Repeat
  5. Pete and Repeat were fishing and Pete fell off the boat. Who was left?
  6.         Stop
  7. */
  8. import java.util.Scanner;
  9.  
  10. public class WhileLoop3{
  11.    public static void main(String[] args){
  12.       Scanner kb = new Scanner(System.in);
  13.       System.out.print("Pete and Repeat were fishing and Pete fell off the boat. Who was left?");
  14.       String answer = kb.next();
  15.      
  16.       while( !answer.equals("stop") && !answer.equals("Stop") ){
  17.          System.out.print("Pete and Repeat were fishing and Pete fell off the boat. Who was left?");
  18.          answer = kb.next();
  19.       }
  20.    }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement