Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class TwoDArr
- {
- private static int len;
- public static void main(String[] args)
- {
- String[] words = entry();
- String[][] wordSub = findSub(words);
- //System.out.println(wordSub[2][1]);
- for(int y = 0; y <= words.length-1; y++)
- {
- System.out.print(words[y] + ", ");
- }
- System.out.println();
- int y;
- for(y = 0; y <= words.length - 1; y++)
- {
- for(int h = 0; h <= words[y].length() - 1; h++)
- {
- System.out.print(wordSub[y][h] + ", ");
- }
- System.out.println();
- }
- }
- public static String[] entry()
- {
- len = Integer.parseInt(JOptionPane.showInputDialog(null, "How many words?", "Number of Words", JOptionPane.QUESTION_MESSAGE));
- String[] words = new String[len];
- for(int x = 0; x <= len-1; x++)
- {
- words[x] = JOptionPane.showInputDialog(null, "ENTER A WORD: ", "Entry", JOptionPane.QUESTION_MESSAGE);
- }
- return(words);
- }
- public static String[][] findSub(String[] words)
- {
- int l = 0;
- for(int y = 0; y <= words.length-1; y++)
- {
- if(words[y].length() > l)
- {
- l = words[y].length();
- }
- }
- //String[][] subs = new String[words.length][(l*(l+1))/2];
- int jk = 0;
- String[][] subs = new String[words.length][((l*(l+1))/2) + jk];
- int ul = 0;
- int hl = 0;
- for(int y = 0; y <= words.length-1; y++)
- {
- for(int x = 0; x <= words[y].length()-1; x++)
- {
- for(int z = x; z <= words[y].length()-1; z++)
- {
- if(z == x)
- {
- subs[y][ul] = words[y].substring(x, x+1);
- }
- else
- {
- subs[y][ul] = words[y].substring(x, z+1);
- }
- ul++;
- }
- }
- ul = 0;
- }
- return(subs);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement