I am having some trouble assigning values to my letter array. I need a char array that consists of all letters and have a default value of the position in the alphabet.
Meaning the letter 'A' would have a value of 1 and letter 'B' have a value of 2 and letter 'C' would have a value of 3..etc.
And then the user would pick what letters they want to assign values. Meaning they could input:
C = -13
X = 5
H = 25
D = 4
And only those letters would have values that change. I then need to apply these values to an expression.
if my expression is: A*H+C
then my result is: 12
because: (1)(25)+-13=12
EDIT: The end goal of the program is to evaluate the expression by using the values that the user entered for the variables and if they have not specified a value to use the default values that i assigned in the array to evaluate the expression. The answer must be a type int and i must use arrays or stacks.
The user can input the following:
C = -13
X = 5
H = 25
D = 4
A*H+C
The output should be:
Result: 12
The default values of the letters must be the following:
A=1
B=2
C=3
. . . Z= 26
Character[] letterArray = new int [26];
//to fill the array initially with values
for( int i =0; i <letterArray.length; i ++){
letterArray[i]= 66-(int)'A'
}
for(int j = 0 j <letterArray ; j++){
String input = keyboard.nextLine();//to fill in specific values
}