Reputation: 125
Hello all and thanks for taking the time to look at my question. I'm working on my Java homework (I understand the rules and I don't want you to do my homework, I'm just very stuck and am very confused so please to ban/yell at/poke me)
I have a class called Encryption. I'm calling this class in a Panel, which is being put into a Frame.
I need to read in user input and 'encrypt' that string with my own system using an Array.
I have read my book and searched for answers but I don't know why my INT array is returnign all O's. My Char array is returning the correct Char when I debug it, but my Int array is returning all 0's.
Here is what I have, any advice or suggestions is much appreciated.
Thanks
import java.util.Scanner;
public class Encryption {
private String finalEncryption;
int [] numArray = new int[25];
char[] charArray = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char current;
//constructor
public Encryption(){
}
public String toString(){
return finalEncryption;
}
public String setEncryption(String entry){
String newEntry = entry.toUpperCase();
//loop to go through each letter in the string
for (int ch = 0; ch < newEntry.length(); ch++)
{
current = newEntry.charAt(ch);
//loop to go through each letter in the alphabet
for (int i=0; i < 26; i++)
{
if(current == charArray[i])
{
int finalEntry = numArray[i];
System.out.println(finalEntry);
}
else if (current == numArray[i])
{
}
}
System.out.println(current);
}
return entry;
}
}
Upvotes: 1
Views: 1377
Reputation: 8146
Everything in Java not explicitly set to something, is initialized to a zero value.
int that is a 0.
Refer this document.
Upvotes: 1
Reputation: 59611
An int array defaults to all zero's after you initialize it - this appears to be your case. Nowhere are you setting any values in the int array, you are only initializing it, and then reading it.
Upvotes: 3