Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String command = "";
- String parameter = "";
- Scanner dataIn = new Scanner(System.in);
- while (!command.equals("exit")) {
- System.out.print(">> ");
- command = dataIn.next().trim();
- parameter = dataIn.next().trim();
- //should ^ these have error handling?
- if (command.equals("dothis")) {
- //do this w/ parameter..
- } else if (command.equals("dothat")) {
- //do that w/ parameter..
- } //else if... {}
- else {
- system.out.println("Command not valid.");
- }
- }
- System.out.println("Program exited by user.");
- Scanner sc = new Scanner(System.in);
- for (prompt(); sc.hasNextLine(); prompt()) {
- String line = sc.nextLine().replaceAll("n", "");
- // return pressed
- if (line.length == 0)
- continue;
- // split line into arguments
- String[] args = line.split(" ");
- // process arguments
- if (args.length == 1) {
- if (args[0].equalsIgnoreCase("exit"))
- System.exit(0);
- if (args[0].equalsIgnoreCase("dosomething"))
- // do something
- } else if (args.length == 2) {
- // do stuff with parameters
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement