我需要使用 getAverage 方法和 main 方法创建一个程序,让用户输入五个字符,然后计算/打印平均 ASCII 值和最高字母,但是 Eclipse 给了我很多错误,我不太确定我在做什么
public static int getAverage(char [] ascii, int [] decimal, int [] letters) {
{
System.out.println("Enter 5 letters from the English Alphabet: ");
Scanner input = new Scanner(System.in);
我正在尝试将这封信作为 ASCII 数字存储在这里
System.out.println("Letter 1 (a-z or A-Z): ");
char a = (input.next()).charAt(0);
int letterOne = -1;
for(int i=0; i<ascii.length; i++){
if (ascii[i] == a)
letterOne=i;
}
System.out.println("Letter 2 (a-z or A-Z): ");
char b = (input.next()).charAt(0);
int letterTwo = -1;
for(int i=0; i<ascii.length; i++){
if (ascii[i] == b)
letterTwo=i;
}
System.out.println("Letter 3 (a-z or A-Z): ");
char c = (input.next()).charAt(0);
int letterThree = -1;
for(int i=0; i<ascii.length; i++){
if (ascii[i] == c)
letterThree=i;
}
System.out.println("Letter 4 (a-z or A-Z): ");
char d = (input.next()).charAt(0);
int letterFour = -1;
for(int i=0; i<ascii.length; i++){
if (ascii[i] == d)
letterFour=i;
}
System.out.println("Letter 5 (a-z or A-Z): ");
char e = (input.next()).charAt(0);
int letterFive = -1;
for(int i=0; i<ascii.length; i++){
if (ascii[i] == e)
letterFive=i;
}
我不知道如何将这些变成我可以在主中使用的数组
int[] letter = new int{letterOne, letterTwo, letterThree, letterFour, letterFive};
int [] lettersArray = {a, b, c, d, e};
int average = ((a+b+c+d+e)/5);
System.out.println("Your average value is: " + average);
如果有的话,不确定要在这里返回什么?
return ;
}
public static void main(String[] args)
{
int [] decimalArray = new int[52];
char[] asciiArray = new char[52];
int base = 65;
for (int i=0; i<26;i++){
decimalArray[i] = base;
asciiArray[i] = (char) base;
base++;
}
base = 97;
for(int i = 26; i<52; i++){
decimalArray[i] = base;
asciiArray[i] = (char) base;
base++;
}
int [] lettersArray = new int[5];
不知道如何在此处从 CHAR 更改为 INT
int[] letters = new int[5];
char max = letters[0]
for(int i = 0; i<5; i++){
if(max < letters[i])
max = letters[i];
}
getAverage(asciiArray, decimalArray, lettersArray);
System.out.println("The highest letter is: " + max);
}
}