AliceAndBob.java 1.1KB

123456789101112131415161718192021222324252627282930
  1. import java.util.*;
  2. /**
  3. * This program will do the following:
  4. * Firstly ask the user to input his/her name. Then find a way to check the person's name to see if it is Bob or Alice.
  5. * If the user's name is either Alice or Bob; then a greeting will be printed to the screen.
  6. */
  7. public class AliceAndBob {
  8. /* The Scanner class is used as a simple text scanner which can parse/analyze a sentence in parts.
  9. * In this case Scanner is used to scan the user's input to check for something specific.
  10. *System.out.print ("What is your name?"); ---> this prints "What is your name?" to the console and this prompts the user to input his/her name.
  11. * String name = in.nextLine---> this will print the entire line that that the user enters.
  12. */
  13. public static void main(String[] args ){
  14. Scanner in = new Scanner(System.in);
  15. System.out.print("What is your name?");
  16. String name = in.nextLine();
  17. //If the user's name is equivalent to Alice or Bob; then print "Hi!"
  18. if(name.equals("Alice") || name.equals("Bob")){
  19. System.out.println("Hi!");
  20. }
  21. }
  22. }