Advertisement
Guest User

Advanced Java - Simple Text Editor

a guest
May 23rd, 2016
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by soki on 20-May-16.
  7.  */
  8. public class CalculateSequenceWithQueue {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         String text = "";
  12.         int numInputLines = scanner.nextInt();
  13.         int countToErase;
  14.         int indexToReturn;
  15.         byte lastOperationType ;
  16.         for (int i = 0; i < numInputLines; i++) {
  17.             String[] command = scanner.nextLine().split(" ");
  18.             switch (command[0]) {
  19.                 case "1":
  20.                     text.concat(command[1]);
  21.                     break;
  22.                 case "2":
  23.                     countToErase = Integer.parseInt(command[1]);
  24.                     text = text.substring(0,text.length() - countToErase);
  25.                     break;
  26.                 case "3":
  27.                     indexToReturn = Integer.parseInt(command[1]);
  28.                     System.out.println(text.charAt(indexToReturn - 1));
  29.                     break;
  30.                 //case 4 - undoes last case 1 or 2 operation
  31.                 case "4":
  32.                     break;
  33.  
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement