timetraveller1992

ExpandCipher

Nov 12th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class ExpandCipher {
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.         Scanner scan = new Scanner(System.in);
  9.         System.out.println("Input the encrypted string");
  10.         String sInput = scan.nextLine();
  11.         scan.close(); // Free scanner since we no longer need to get data
  12.         String s[] = sInput.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
  13.         char cI = 0;
  14.         for(String s1:s)
  15.         {
  16.             if(!Character.isDigit(s1.charAt(0)))
  17.                 cI = s1.charAt(0);
  18.             else
  19.                 {
  20.                     int repeat = Integer.parseInt(s1);
  21.                     for(int i = 0; i < repeat; i++)
  22.                         System.out.print(cI);
  23.                 }
  24.         }
  25.        
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment