Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    13
    Rep Power
    0

    Default What am I doing wrong?

    I need help, I'm trying to create a program to Encipher words and phrases but it doesn't output what I want it to.
    Heres the code
    Java Code:
    import java.util.Scanner;
    public class Cipher 
    {
       public static void main(String[] args)
        {
            Scanner keyboard = new Scanner(System.in);
            String Input;
            String Output = "";
            System.out.println("Input Word");
            String Encipher = keyboard.nextLine(); 
            Encipher.replaceAll("\\s",""); 
             
            Integer EncipherPosition = 0;
            String Cipher = "";
            for (EncipherPosition = 0; EncipherPosition < Encipher.length(); EncipherPosition ++)
                {
                    char EncipherChar = Encipher.charAt(EncipherPosition);
                    String EncipherString = "" + EncipherChar;
                    boolean temp = Cipher.contains(EncipherString);
                    if (temp == false)
                        {
                            Cipher += Encipher.charAt(EncipherPosition);
                        }   
                }
            System.out.println("This is what you Input: " + Cipher);
            
            String alphabet = "abcdefghijklmnopqrstuvwxyz";
            //sets the alphabet string
            Integer alphabetPosition = 0;
            for (alphabetPosition = 0;alphabetPosition < alphabet.length();alphabetPosition ++)
                {
                    char alphabetTempChar = alphabet.charAt(alphabetPosition);
                    String alphabetTempString = "" + alphabetTempChar;
                    boolean alphabetTemp = Cipher.contains(alphabetTempString);
                    if (alphabetTemp == false)
                        {
                            Cipher += alphabet.charAt(EncipherPosition);
                        }
                }
             
            System.out.println("This is your ciphered text" + Cipher + alphabet + Cipher);
            System.out.println("Input message:");
            Input = keyboard.nextLine();
             
            Integer position = 0;
            for (position = 0; position < alphabet.length(); position ++)
                {
                    char CipherChar = Cipher.charAt(position);
                    String CipherString = "" + CipherChar;
                    char alphabetChar = alphabet.charAt(position);
                    String alphabetString = "" + alphabetChar;
                    Input.replace(alphabetString,CipherString);
                }
            System.out.println("This is your encoded message : " + Input);
            }
    }
    And this is what it outputs if I enter "Testing" and "Testing one two three" when it asks for input
    Java Code:
    Input Word
    Testing
    This is what you Input: Testing
    This is your ciphered textTestinghhhhhhhhhhhhhhhhhhhabcdefghijklmnopqrstuvwxyzTestinghhhhhhhhhhhhhhhhhhh
    Input message:
    Testing one two three
    This is your encoded message : Testing one two three

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: What am I doing wrong?

    User banned for one week for asking to pay others to do his homework for him. Cheating is not allowed on this forum.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: What am I doing wrong?

    Make that a permanent ban for trying to get around the original ban.

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. what am i doing wrong here :(
    By repooc in forum New To Java
    Replies: 2
    Last Post: 08-20-2011, 02:34 AM
  3. What did I do wrong?
    By GoingThroAPhase in forum New To Java
    Replies: 4
    Last Post: 04-03-2010, 04:51 AM
  4. what's wrong here ?
    By doha786 in forum New To Java
    Replies: 6
    Last Post: 03-26-2010, 12:21 PM
  5. what am i doing wrong here?
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-21-2010, 04:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •