Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Numbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] command = scanner.nextLine().trim().split(" ");
- String num = new String();
- String keeper = new String();
- while(true)
- {
- if (command[0].contains("end"))
- {
- break;
- }
- if (command[0].contains("set"))
- {
- num = command[1];
- }
- else if (command[0].contains("front-add"))
- {
- num = command[1]+num;
- }
- else if (command[0].contains("front-remove"))
- {
- num = num.substring(1);
- }
- else if(command[0].contains("back-add"))
- {
- num = num + command[1];
- }
- else if(command[0].contains("back-remove"))
- {
- num = num.replace(num.substring(num.length()-1), "");
- }
- else if (command[0].contains("reverse"))
- {
- keeper = num;
- num = new String();
- for(int i=keeper.length()-1; i>=0; i--) {
- num = num + keeper.charAt(i);
- }
- }
- else if (command[0].contains("print"))
- {
- System.out.println(num);
- }
- command = scanner.nextLine().trim().split(" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement