Advertisement
Guest User

ARR

a guest
Jan 28th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class TwoDArr
  4. {
  5. private static int len;
  6.  
  7. public static void main(String[] args)
  8. {
  9. String[] words = entry();
  10. String[][] wordSub = findSub(words);
  11. //System.out.println(wordSub[2][1]);
  12.  
  13. for(int y = 0; y <= words.length-1; y++)
  14. {
  15. System.out.print(words[y] + ", ");
  16.  
  17. }
  18. System.out.println();
  19. int y;
  20. for(y = 0; y <= words.length - 1; y++)
  21. {
  22. for(int h = 0; h <= words[y].length() - 1; h++)
  23. {
  24. System.out.print(wordSub[y][h] + ", ");
  25. }
  26. System.out.println();
  27. }
  28.  
  29.  
  30. }
  31. public static String[] entry()
  32. {
  33.  
  34. len = Integer.parseInt(JOptionPane.showInputDialog(null, "How many words?", "Number of Words", JOptionPane.QUESTION_MESSAGE));
  35. String[] words = new String[len];
  36.  
  37. for(int x = 0; x <= len-1; x++)
  38. {
  39. words[x] = JOptionPane.showInputDialog(null, "ENTER A WORD: ", "Entry", JOptionPane.QUESTION_MESSAGE);
  40. }
  41. return(words);
  42. }
  43. public static String[][] findSub(String[] words)
  44. {
  45. int l = 0;
  46. for(int y = 0; y <= words.length-1; y++)
  47. {
  48.  
  49. if(words[y].length() > l)
  50. {
  51. l = words[y].length();
  52. }
  53. }
  54.  
  55. //String[][] subs = new String[words.length][(l*(l+1))/2];
  56.  
  57. int jk = 0;
  58.  
  59.  
  60. String[][] subs = new String[words.length][((l*(l+1))/2) + jk];
  61. int ul = 0;
  62. int hl = 0;
  63.  
  64.  
  65. for(int y = 0; y <= words.length-1; y++)
  66. {
  67. for(int x = 0; x <= words[y].length()-1; x++)
  68. {
  69. for(int z = x; z <= words[y].length()-1; z++)
  70. {
  71. if(z == x)
  72. {
  73. subs[y][ul] = words[y].substring(x, x+1);
  74. }
  75. else
  76. {
  77. subs[y][ul] = words[y].substring(x, z+1);
  78. }
  79. ul++;
  80. }
  81.  
  82. }
  83. ul = 0;
  84. }
  85.  
  86.  
  87. return(subs);
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement