大写从java中的扫描仪输入的字符串 [英] Uppercase a string input from scanner in java

查看:46
本文介绍了大写从java中的扫描仪输入的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该使用 Java 中的 Scanner 来接收 14 个字符的输入,并以大写格式输出所有字母字符.我尝试输入我通过 Google 找到的一些代码,例如"str.toUpperCase(Locale.ENGLISH); ",但它告诉我 str 无法解析并且语言环境无法解析.当我在这里搜索时,我得到了大写特定字符或计数字符的结果.我只需要将特定的输入行大写.

I am supposed to use the Scanner in Java to receive a 14 char input and have all the letter char output in uppercase format. I've tried entering some of the code I found through Google such as " str.toUpperCase(Locale.ENGLISH); " but it tells me str cannot be resolved and that the locale can't be resolved. When I did a search on here I got results for uppercasing specific char or counting char. I just need the specific line of input to be uppercased.

以下是我目前所拥有的.我正在使用 eclipse java neon

The following is what I have at the moment. I am using eclipse java neon

  import java.util.Scanner;

public class MemberIDLotz {
    // Everette Lotz
    public static void main(String[] args) {
        Scanner string = new Scanner(System.in);

        // We're going to get a 14 char string from a user.
        System.out.println("Please enter in a 14 character long ID");
        String name = string.next();
        str.toUpperCase(Locale.ENGLISH);

        string.close();
    }
}

提前感谢您的帮助.

*好的,所以它不再给我一条错误消息,是的,我只是简单地复制并粘贴了代码.但是,当它打印出来时,它不是大写格式.我将以下内容放在String name =...."之后,并删除了 str.toUppercase() 行:

* Ok so it is no longer giving me an error message, and yes I had simply copy and pasted the code. However when it prints out its not in upper case format. I put the following right after "String name =...." and deleted the str.toUppercase() line:

System.out.println(name);
name = name.toUpperCase();`

推荐答案

是否有理由不立即大写?

Is there a reason you don't uppercase immediately?

String name = string.next().toUpperCase()

这篇关于大写从java中的扫描仪输入的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆