import java.util.Scanner;
import java.util.Date;
public class Test {
public static void main(String[] args) {
Action action = new Action();
Scanner scanner = new Scanner(System.in);
String in;
do {
System.out.print("> ");
in = scanner.nextLine();
action.process(in);
} while (!in.equals("quit"));
}
}
class Action {
public Action() {
}
public void process(String in) {
switch(in) {
case "date": date(); break;
}
}
public void date() {
System.out.println(new Date().toString());
}
}
Wednesday, July 29, 2020
Do While Loop / Switch Statement
Here we have a simple do/while loop with the input from a Scanner going to a switch statement.
Subscribe to:
Post Comments (Atom)
Ever feel like no one is listening?
Ever have that feeling that no one is listening to you? Yeah, that feeling. It can be a strong feeling to have, a hurtful feeling also. The...
-
Ever have that feeling that no one is listening to you? Yeah, that feeling. It can be a strong feeling to have, a hurtful feeling also. The...
-
Let's face it, this life isn't easy. Ther are things that we must do daily in order to survive. It can feel like you don't have...
-
Here's an easy method to return yesterday's date: import java.time.LocalDateTime; public class DoIt { public static void mai...
No comments:
Post a Comment