Start with an infinite while loop for the program.
while(true) {
add if statements to detect commands and some other things.
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Example { public static void main(String[] args) throws IOException { while (true) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String command = ""; command = in.readLine(); // These are your commands. if (command.equalsIgnoreCase("FirstCommand")) { System.out.println("My first Command!"); } else if (command.equalsIgnoreCase("SecondCommand") || command.equals("AlternativeSecondCommand")) { System.out.println("My second command!"); } else if (command.equalsIgnoreCase("ThirdCommand" + "ParameterOne")) { System.out.println("Parameter one of command three!"); } else if (command.equalsIgnoreCase("Stop") || command.equalsIgnoreCase("Exit") || command.equalsIgnoreCase("Quit")) { System.exit(0); } else { System.out.println("Error: Unknown Command"); } } } }
just add if statements for more commands.
It works great and its very easy for beginners. Give it a try!
Asbestos man
source share