Advertisement
Guest User

Untitled

a guest
Oct 24th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. Scanner in = new Scanner(System.in);
  2. System.out.println("This program will generate all the substrings of a given word, in increasing order of substring length.");
  3. System.out.println();
  4. System.out.printf("Please enter the word: ");
  5. String word = in.next();
  6. //String strFormatHeader = "| " + word + " | ";
  7. //System.out.println(wordFormatHeader);
  8. //int numDashes = 7 + Integer.parseInt(word);
  9. String dashes = "";
  10. int i = 1;
  11. int j;
  12.  
  13. System.out.print("|");
  14.  
  15. while (i <= word.length()){
  16. for (j = 0; j < word.length()-i;j++)
  17. {
  18. System.out.printf("%s|", word.substring(j,i));
  19. i++;
  20.  
  21. }
  22.  
  23.  
  24.  
  25. }
  26. }
  27. /* for (i = 0; i < word.length(); i++)
  28. {
  29. //for (j = 0; j < word.length(); j += 1)
  30. System.out.printf("%s|", word.charAt(i));
  31. }
  32. {
  33. System.out.println();
  34. }
  35. for (i = 0; i < word.length(); i++){
  36. System.out.printf("%s|", word.substring(0,i));
  37. i += 1;
  38.  
  39.  
  40.  
  41. }
  42. System.out.println();
  43. System.out.printf("|%s|",word);
  44.  
  45. //}
  46. /*for (i = 0; i < word.length(); i++)
  47. {
  48. char c = word.charAt(i);
  49. // System.out.printf("-");
  50. dashes = dashes + "-";
  51. System.out.println(dashes);
  52. String strFormatHeader = "| " + word + " | ";
  53. System.out.println(strFormatHeader);
  54. }
  55. System.out.println(dashes);
  56. //String strFormatHeader = "| " + word + " | ";
  57. //System.out.println(strFormatHeader);
  58. }*/
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement