SHARE
TWEET

String Explosion

a guest Mar 23rd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class StringExplosion_07 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String input = scanner.nextLine();
  10.  
  11.         StringBuilder result = new StringBuilder();
  12.  
  13.         int power = 0;
  14.  
  15.         for (int i = 0; i < input.length();) {
  16.  
  17.             if (input.charAt(i) != '>') {
  18.  
  19.                 result.append(input.charAt(i));
  20.                 i++;
  21.             } else {
  22.  
  23.                 result.append('>');
  24.                 i++;
  25.                 power += Integer.parseInt(String.valueOf(input.charAt(i)));
  26.  
  27.                 while (power > 0) {
  28.                     i++;
  29.                     power--;
  30.  
  31.                     if (i == input.length() || input.charAt(i) == '>') {
  32.                         break;
  33.                     }
  34.                 }
  35.             }
  36.  
  37.         }
  38.         System.out.println(result);
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top