Skip to content

Instantly share code, notes, and snippets.

@aaayushsingh
Created December 9, 2017 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaayushsingh/0dd6552e340de8603a9bf98962435128 to your computer and use it in GitHub Desktop.
Save aaayushsingh/0dd6552e340de8603a9bf98962435128 to your computer and use it in GitHub Desktop.
stringSplit
public class JavaApplication15 {
/**
* @param args the command line arguments
*/
static String input = "I am testing an string split program here and there is some problem";
public static void main(String[] args) {
// TODO code application logic here
input += " dummyinputtohackresult";
System.out.println(input);
String[] a = input.split(" ");
String op = "";
int i=0, size=0, breakup = 10;
while(i<a.length-1 && size <= breakup){
size += a[i].length() + 1;
op = op + a[i] + " ";
if(size+a[i+1].length() - 1 > breakup){
System.out.println(op);
size = 0;
op = "";
}
//System.out.println("Current String: " + op);
i++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment