Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Write a method which gets a String from the user, and returns it.
  3. Your method signature is :
  4. public static String getString()
  5.  
  6. Write another method which checks if the word "rabbit" is in the passed String parameter.
  7. If the "rabbit" is present, it prints "It seems you would like to talk about rabbits".
  8. If "rabbit" is not present, it prints "Why don't we talk about rabbits, instead?"
  9. Your method signature is:
  10. public static void checkForRabbits(String param)
  11. { ...
  12. }
  13.  
  14. In your main method; call getString() to get the user input. Call checkForRabbits() with the String from getString().
  15. */
  16.  
  17.  
  18. import java.util.*;
  19.  
  20. public class Unit4ReviewQuestion8 {
  21.  
  22.     private static Scanner text;
  23.    
  24.     public static void main(String[] args) {
  25.         // TODO Auto-generated method stub
  26.        
  27.         System.out.println("What would you like to talk about?");
  28.        
  29.         text = new Scanner(System.in);
  30.         String path = text.next();
  31.    
  32.         String Rabbit = "rabbit";
  33.        
  34.         if (path.equals(Rabbit)) {
  35.             System.out.println("It seems you would like to talk about rabbits");
  36.         } else {
  37.             System.out.println("Why don't we talk about rabbits instead");
  38.         }
  39.  
  40.        
  41.        
  42.     }
  43.    
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement