将小写字母传递为等效的大写字母,而不使用 toUpperCase () 方法
我一直在努力尝试却没有办法。
我想将小写字母转换为大写字母。
我知道并且知道如何使用 toUpperCase() 方法,但我不想使用它。
这是我失败的代码:
import java.util.Scanner;
public class ConvertLetters {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.print("enter a lower case letter");
char letter = stdin.nextLine();
int letter2 = 'A' + (letter - 'a');
System.out.println("and we will refund your letter capitalized");
System.out.print("Your letter: " + letter);
System.out.print("upper case equates to:");
System.out.print(letter2);
}
}
I've been trying and trying and there is no way.
I want to spend a lowercase letter to uppercase equivalent.
I know and know how to use the method toUpperCase () but I want to do without it.
This is my failing code:
import java.util.Scanner;
public class ConvertLetters {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
System.out.print("enter a lower case letter");
char letter = stdin.nextLine();
int letter2 = 'A' + (letter - 'a');
System.out.println("and we will refund your letter capitalized");
System.out.print("Your letter: " + letter);
System.out.print("upper case equates to:");
System.out.print(letter2);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想以
char
或
You want to finish with a
char
or
我发现这段代码有两个问题。首先,分配
nextLine()
,它是一个字符串。你可能想要类似的东西。其次,你打印
int
,尝试通过这些更改,我认为你的代码会给你更好的结果。
当然,无论如何,这对非 ASCII 字符不起作用。
I see two problems with this code. First, you assign
nextLine()
, which is a string. You may want something likeinstead. Second, you print
int
, tryWith these changes, I think your code will give you better results.
Naturally, that won't work for non-ascii characters, anyway.