Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class Numbers {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. String[] command = scanner.nextLine().trim().split(" ");
  10. String num = new String();
  11. String keeper = new String();
  12. while(true)
  13. {
  14.  
  15. if (command[0].contains("end"))
  16. {
  17.  
  18. break;
  19. }
  20. if (command[0].contains("set"))
  21. {
  22. num = command[1];
  23. }
  24. else if (command[0].contains("front-add"))
  25. {
  26.  
  27. num = command[1]+num;
  28. }
  29. else if (command[0].contains("front-remove"))
  30. {
  31. num = num.substring(1);
  32. }
  33. else if(command[0].contains("back-add"))
  34. {
  35.  
  36. num = num + command[1];
  37. }
  38. else if(command[0].contains("back-remove"))
  39. {
  40. num = num.replace(num.substring(num.length()-1), "");
  41.  
  42. }
  43. else if (command[0].contains("reverse"))
  44. {
  45. keeper = num;
  46. num = new String();
  47. for(int i=keeper.length()-1; i>=0; i--) {
  48. num = num + keeper.charAt(i);
  49. }
  50.  
  51.  
  52.  
  53. }
  54. else if (command[0].contains("print"))
  55. {
  56. System.out.println(num);
  57. }
  58. command = scanner.nextLine().trim().split(" ");
  59.  
  60. }
  61.  
  62.  
  63.  
  64. }
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement