Need a program which print out every Symbol of the command line arguments and the fitting argument

Viewed 17

my program should print out every symbol in the Set inclusive the fitting command line parameters . So I wrote this :

    public static void main(String[] args) {
        HashSet<Character> mySet = new HashSet<Character>();
        
        for(int i = 0; i < args.length; ++i) {
            for(int j = 0; j < args[i].length(); ++j) {
                mySet.add(args[i].charAt(j));
            }
        }
        Iterator<Character> iter = mySet.iterator(); 
        while (iter.hasNext()) { 
            Character s = iter.next(); 
            System.out.print("Zeichen: " + s + " - Kommadozeilenparamter:[");
            for(int i = 0; i < args.length; ++i) {
                if(args[i].indexOf(s) > 0) {
                            System.out.print(" " + args[i]);
                }
                
            }
            System.out.print(" ]");
            System.out.println();
         }

That's not the best and smartest way to do this task...I'm a beginner ;( When I do the input like : ab bca cd -> then I should get : [Kommandozeilenparamter is German for command line parameters / Zeichen ist German for symbol]

Zeichen: a - Kommadozeilenparamter:[ ab bca ]
Zeichen: b - Kommadozeilenparamter:[ ab bca ]
Zeichen: c - Kommadozeilenparamter:[ bca cd ]
Zeichen: d - Kommadozeilenparamter:[ cd ]

but I got:

Zeichen: a - Kommadozeilenparamter:[ bca ]
Zeichen: b - Kommadozeilenparamter:[ ab ]
Zeichen: c - Kommadozeilenparamter:[ bca ]
Zeichen: d - Kommadozeilenparamter:[ cd ]
0 Answers
Related