-1

I've been basically trying to get this problem days but can't get it finished.

I have an user input of integer. Then user enters a string. Let say the inputted string is 'ok, ok, okay'. I need to get the printed output to cut the strings after every , or . Then let's say the inputted integer was 10. So after every line i need 10-ok,(3) = 7 spaces and one \ in the end. How do i do this?

so the output would look like this:

ok,      /
ok,      /
okay,    /

Any help would be appreciated! Thanks in advance!

Ravi
  • 30,829
  • 42
  • 119
  • 173

1 Answers1

0
public class MyStrangeClass{

  public static void main(String[] args){
    String input = "ok, ok, okay. ok";
    System.out.println(test(10,input));

  }

  public static String test(int arg1, String arg2){
    String[] tokens = arg2.split("[,.]");
    int res = arg1 - tokens.length;
    String resString = "";
    for (int i=0;i<tokens.length; i++){
      String spaces = String.format("%0" + res + "d", 0).replace("0"," ");
      resString = resString+tokens[i]+','+spaces+"/";
    }            

    return resString;
  }
}
Andrea Sindico
  • 7,358
  • 6
  • 47
  • 84