Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. String command = "";
  2. String parameter = "";
  3. Scanner dataIn = new Scanner(System.in);
  4.  
  5. while (!command.equals("exit")) {
  6. System.out.print(">> ");
  7.  
  8. command = dataIn.next().trim();
  9. parameter = dataIn.next().trim();
  10. //should ^ these have error handling?
  11.  
  12. if (command.equals("dothis")) {
  13. //do this w/ parameter..
  14. } else if (command.equals("dothat")) {
  15. //do that w/ parameter..
  16. } //else if... {}
  17. else {
  18. system.out.println("Command not valid.");
  19. }
  20. }
  21.  
  22. System.out.println("Program exited by user.");
  23.  
  24. Scanner sc = new Scanner(System.in);
  25.  
  26. for (prompt(); sc.hasNextLine(); prompt()) {
  27.  
  28. String line = sc.nextLine().replaceAll("n", "");
  29.  
  30. // return pressed
  31. if (line.length == 0)
  32. continue;
  33.  
  34. // split line into arguments
  35. String[] args = line.split(" ");
  36.  
  37. // process arguments
  38. if (args.length == 1) {
  39. if (args[0].equalsIgnoreCase("exit"))
  40. System.exit(0);
  41. if (args[0].equalsIgnoreCase("dosomething"))
  42. // do something
  43. } else if (args.length == 2) {
  44. // do stuff with parameters
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement