<small id='oHjSh'></small><noframes id='oHjSh'>

    <legend id='oHjSh'><style id='oHjSh'><dir id='oHjSh'><q id='oHjSh'></q></dir></style></legend>
  1. <i id='oHjSh'><tr id='oHjSh'><dt id='oHjSh'><q id='oHjSh'><span id='oHjSh'><b id='oHjSh'><form id='oHjSh'><ins id='oHjSh'></ins><ul id='oHjSh'></ul><sub id='oHjSh'></sub></form><legend id='oHjSh'></legend><bdo id='oHjSh'><pre id='oHjSh'><center id='oHjSh'></center></pre></bdo></b><th id='oHjSh'></th></span></q></dt></tr></i><div id='oHjSh'><tfoot id='oHjSh'></tfoot><dl id='oHjSh'><fieldset id='oHjSh'></fieldset></dl></div>
    • <bdo id='oHjSh'></bdo><ul id='oHjSh'></ul>

    1. <tfoot id='oHjSh'></tfoot>

      如何在 Java 中自动将输入字符转换为大写

      时间:2023-07-26
        • <bdo id='iswEn'></bdo><ul id='iswEn'></ul>

                <tbody id='iswEn'></tbody>

              <small id='iswEn'></small><noframes id='iswEn'>

              <tfoot id='iswEn'></tfoot>

              1. <legend id='iswEn'><style id='iswEn'><dir id='iswEn'><q id='iswEn'></q></dir></style></legend>
                <i id='iswEn'><tr id='iswEn'><dt id='iswEn'><q id='iswEn'><span id='iswEn'><b id='iswEn'><form id='iswEn'><ins id='iswEn'></ins><ul id='iswEn'></ul><sub id='iswEn'></sub></form><legend id='iswEn'></legend><bdo id='iswEn'><pre id='iswEn'><center id='iswEn'></center></pre></bdo></b><th id='iswEn'></th></span></q></dt></tr></i><div id='iswEn'><tfoot id='iswEn'></tfoot><dl id='iswEn'><fieldset id='iswEn'></fieldset></dl></div>

                本文介绍了如何在 Java 中自动将输入字符转换为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在使用 Scanner 类来获取输入,并希望在显示时将输入转换为大写字母.这是我的代码

                I am using a Scanner class to get the input and want to convert the input to uppercase letter when display it. This is my code

                Scanner input = new Scanner(System.in);
                System.out.print("Enter a letter: ");
                char c = input.next().charAt(0);
                Character.toUpperCase(c);
                

                由于我已将其转换为大写,但输出类似于

                Since I have convert it to uppercase, but the output is like

                input: a
                c = A;
                output: Enter a letter: a
                

                PS:字母a"是我在终端输入的

                PS: The letter "a" is what I typed in the terminal

                但是我希望它显示为大写字母.我怎样才能改变它?

                However I want to it display as an uppercase one. How can I change it?

                推荐答案

                toUpperCase 方法 不会改变 char 的值(它不能);它返回大写的 char.改变

                The toUpperCase method doesn't change the value of the char (it can't); it returns the uppercased char. Change

                Character.toUpperCase(c);
                

                c = Character.toUpperCase(c);
                

                更新

                更新后的问题现在表明大写字符将在输入时在输入时打印.Java 无法做到这一点,因为 Java 不控制操作系统如何将用户输入回显到屏幕上.我上面的解决方案只会产生额外的输出,即使它是大写的.

                The updated question now indicates that the uppercased characters are to be printed as they're typed. Java cannot do that, because Java doesn't control how the O/S echoes user input to the screen. My solution above would only produce additional output, even if it is uppercased.

                这篇关于如何在 Java 中自动将输入字符转换为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:为什么我不能写 ch=ch+1;而不是 ch++;尽管它们具有 下一篇:将 Char 转换为 double

                相关文章

                最新文章

                  <bdo id='FZ15R'></bdo><ul id='FZ15R'></ul>
                <i id='FZ15R'><tr id='FZ15R'><dt id='FZ15R'><q id='FZ15R'><span id='FZ15R'><b id='FZ15R'><form id='FZ15R'><ins id='FZ15R'></ins><ul id='FZ15R'></ul><sub id='FZ15R'></sub></form><legend id='FZ15R'></legend><bdo id='FZ15R'><pre id='FZ15R'><center id='FZ15R'></center></pre></bdo></b><th id='FZ15R'></th></span></q></dt></tr></i><div id='FZ15R'><tfoot id='FZ15R'></tfoot><dl id='FZ15R'><fieldset id='FZ15R'></fieldset></dl></div>
                <tfoot id='FZ15R'></tfoot>

                <small id='FZ15R'></small><noframes id='FZ15R'>

              2. <legend id='FZ15R'><style id='FZ15R'><dir id='FZ15R'><q id='FZ15R'></q></dir></style></legend>