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

查看:46
本文介绍了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天全站免登陆