123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
-
- /**
- * Write a description of class Hello here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- import java.util.Scanner;
- public class Hello
- {
- // instance variables - replace the example below with your own
- Scanner scan = new Scanner(System.in);
-
-
- /**
- * Constructor for objects of class Hello
- */
- public Hello()
- {
- // initialise instance variables
-
- }
-
- /**
- * An example of a method - replace this comment with your own
- *
- * @param y a sample parameter for a method
- * @return the sum of x and y
- */
- public void greet()
- {
- System.out.println("What is your name?");
- String name = scan.next();
-
- while(!name.equalsIgnoreCase("Alice") ||
- !name.equalsIgnoreCase("Bob")) {
- if (name.equalsIgnoreCase("Alice")) {
- System.out.println("Hello Alice!!");
- } else if (name.equalsIgnoreCase("Bob")) {
- System.out.print("Hey Bob!");
- } else {
- System.out.println("Who is that? Man, I don't know you!");
- }
-
- }
- }
- }
|