Java - 将小写转换为大写而不使用 toUppercase()

Java - Convert lower to upper case without using toUppercase()(Java - 将小写转换为大写而不使用 toUppercase())
本文介绍了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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)