Strings #30 (Boolean: if you don't do what it says it will cancel you out.)

Code

       /// Name: Amir Salehi
    /// Period: 7
    /// Program name: WeaselOrNot
    /// File name: WeaselOrNot.java
    /// Date: Finished 10/3/2015
 import java.util.Scanner;
 
 public class WeaselOrNot
 {
     public static void main( String[] args )
     {
         Scanner keyboard = new Scanner(System.in);
 
         String word;
         boolean yep, nope;
 
         System.out.println( "Type the word \"weasel\", please." );
         word = keyboard.next();
 
         yep  =   word.equals("weasel");
         nope = ! word.equals("weasel");
 
         System.out.println( "You typed what was requested: " + yep );
         System.out.println( "You ignored polite instructions: " + nope );
     }
 }
    

Picture of the output

Assignment 7

Back to Homepage