Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Instance Variable Changes with New Object

    I'm just learning java and I'm writing a program that compares the frequency of characters in a plaintext document and then in a cipher document. I use the frequencies of the letters in each document to find out which character goes with which, in order to decipher a text file.

    I have a class FrequencyAnalysis, which creates an object, with a local variable of char[] key, in which the letters are stored in order of most common occurrence. I create a FrequencyAnalysis object for the plain text document, and the key is stored fine in its array, but when I create a FrequencyAnalysis object for the ciphered text, the key for the plain text document changes to the key for the ciphered document. Why does this happen?
    Thanks.

    I have attached the two classes, FrequencyAnalysis and then the class FrequencyAnalysisTester which creates the objects to this post.
    Attached Files Attached Files

  • #2
    New Coder
    Join Date
    Mar 2011
    Location
    USA
    Posts
    23
    Thanks
    0
    Thanked 1 Time in 1 Post
    because of this..

    private static final char[] alphabet ..

    Remove static, It will work for you(because it worked for me)


  •  

    Posting Permissions

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