3 Replies Latest reply: Oct 23, 2006 12:02 PM by 807598 RSS

    Need help with algorithm

    807598
      I am writing a program to convert a plain message into secret message by using a four letter code word.
      Plain row: ABCDEFGHIJKLMNOPQRSTUVWXYZ

      Below is my code:
      import java.io.*;
      import javax.swing.*;
      public class Q2
      {
            public static void main (String[] args)
            {
      
                boolean found = false;
                String abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                char ch[ ] = new char[26];
              String codeword = args[0]; //code word taken from command line               
                                                               //argument
              for (int x = 0; x < codeword.length(); x++)
              {
                  ch[x] = codeword.charAt(x);
              }
                int next = 4;
                for (int i = 0; i < 26; i++)
                {
                  found = true; //reset boolean found
                    for ( int j = 0; j < 4; j++)
                    {
                       if (abc.charAt(i) == ch[ j ])
                        {     
                            found = true;
                            break;
                        }
                     }
                       if  ( (next < 26) && (found = false) )
                       {
                                     ch[next] = abc.charAt(i);
                                     next++;
                         }
                 }
                System.out.println("Scrambled: " + ch);
                
              String plain = JOptionPane.showInputDialog("Enter message");
              String coded= "\n: coded ";
              for ( int word = 0; word < plain.length(); word ++)
                {
                    char c = plain.charAt(word);
                    int counter = 0;
                    while ( c == abc.charAt(counter))
                    {
                        counter++;
                    }
                    c = ch[counter];
                    System.out.println(+c);
                      counter = 0;
                      
                  }
             }
      }
       
      I have a few queries.
      1) Did i reset boolean 'found' correctly?
      2) When I run the program, only one statment appeared.
      Scrambled: [C@1bb5c09
      3) where did i go wrong?