Java - 不使用toUppercase()将低级转换为大写 [英] Java - Convert lower to upper case without using toUppercase()

查看:234
本文介绍了Java - 不使用toUppercase()将低级转换为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简短的程序,将所有大写的字母转换为小写(从命令行输入)。

I'm trying to create a short program that would convert all letters that are uppercase to lowercase (from the command line input).

以下编译但未给出我期望的结果。这是什么原因?

The following compiles but does not give me the result I am expecting. What would be the reason for this??

例如)java toLowerCase BANaNa - >给出香蕉的输出

Eg) java toLowerCase BANaNa -> to give an output of banana

 public class toLowerCase{
        public static void main(String[] args){

            toLowerCase(args[0]);
        }

        public static void toLowerCase(String a){

            for (int i = 0; i< a.length(); i++){

                char aChar = a.charAt(i);
                if (65 <= aChar && aChar<=90){
                    aChar = (char)( (aChar + 32) ); 
                }

                System.out.print(a);
            }
         }   
    }


推荐答案

看起来像我的作业,只是一个暗示。您正在打印字符串 a ,而您正在修改 char 键入 aChar ,它没有修改原始字符串 a 。 (记住字符串是不可变的)。

Looks like homework to me, Just a hint. You are printing string a whereas you are modifying the char type aChar, its not modifying the original string a. (Remember strings are immutable).

这篇关于Java - 不使用toUppercase()将低级转换为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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