java如何将数字转换为字母(A=0、B=1、C=2等)
事实上我很抱歉代码不完整我想这可能更好。。我想要的是在算法完成后,我希望能够打印出数字输出,并将数字输出转换为字母。。很可能就像密码一样
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
String ct;
String k;
int sum = 0;
System.out.print("Enter Text: ");
ct = scanner.nextLine();
int arr1[] = new int[ct.length()];
for(int j = 0; j < ct.length(); j++)
{
arr1[j] += ( (int)ct.charAt(j) - 97);
System.out.println("Value of Text at["+j+"]: "+arr1[j]);
}
//user input key
System.out.print("Enter random word: ");
k = scanner.nextLine();
for(int i = 0; i < k.length(); i++)
{
System.out.println( (int)k.charAt(i) - 97 );
sum = sum + ( +(int)k.charAt(i) - 97 );
}
System.out.println("Sum of all letter in the random word: "+sum);
for(int i = 0; i < ct.length(); i++)
{
System.out.print(arr1[i]+ " ");
arr1[i] += sum;
if(arr1[i] > 25)
{
arr1[i] -= 25;
if(arr1[i] > 25)
{
arr1[i] -= 25;
}
}
}
System.out.println();
for(int i = 0; i < ct.length(); i++)
{
System.out.print(arr1[i]+ " ");
}
}
输出
Enter Text: kind
Value of Text at[0]: 10
Value of Text at[1]: 8
Value of Text at[2]: 13
Value of Text at[3]: 3
Enter random word: evil
4
21
8
11
Sum of all letter in the random word: 44
10 8 13 3
4 2 7 22
# 1 楼答案
如果你想做这样的事,请告诉我
如果输入为:
evil
输出将是:
Value of the text at [0]: 4
Value of the text at [1]: 21
Value of the text at [2]: 8
Value of the text at [3]: 11
# 2 楼答案
您可以创建一个方法:
你可以调用这个方法:
使用0,返回一个 等等