这是我的一道课后练习题,要求大小写字母互相转换并计数转换的个数,我写完了,小写能换成大写,大写却转换不成小写,希望大家不要嫌这个问题菜不予回答。
class Convert{
public static void main(String args[])
throws java.io.IOException{
char ch;
int count=0;
do{
do{
ch=(char)System.in.read();
}while(ch == '\n'|ch == '\r');
if (ch!='.'){
if(ch<'A'&ch>='a') {
ch+=32;
count+=1;
}
if(ch>='A'&ch<'Z'){
ch-=32;
count+=1;
}
System.out.println("The convert char is"+ch);
}
}while(ch!='.');
System.out.println("The numbers of convert is:"+count);
}
}

解决方案 »

  1.   

    你的程序有几个问题,比如把“&&”写成了“&”,把“||”写成了“|”,if语句的判断范围也写错了,等等。程序修改如下:class Convert {
        public static void main(String args[]) throws java.io.IOException {
            char ch;
            int count = 0;
            do {
                System.out.print("Please input a letter(input . to end the program): ");
                do {
                    ch = (char) System.in.read();
                } while (ch == '\n' || ch == '\r');
                if (ch != '.') {
                    if (ch >= 'a' && ch <= 'z') {
                        ch -= 32;
                    } else if (ch >= 'A' && ch <= 'Z') {
                        ch += 32;
                    } else {
                        System.out.println("It's not a letter.");
                        continue;
                    }
                    count++;
                    System.out.println("The convert char is: " + ch);
                }
            } while (ch != '.');
            System.out.println("The numbers of convert is:" + count);
        }
    }
      

  2.   

    JAVA话用字符串,toLowerCase()使用默认语言环境的规则将此 String 中的所有字符都转换为小写。toUpperCase()使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
      

  3.   

    class Convert{
    public static void main(String args[])
    throws java.io.IOException{
    char ch;
    int count=0;
    do{
    do{
    ch=(char)System.in.read();
    }while(ch == '\n'|ch == '\r');
    if (ch!='.'){
    if((ch<='Z')&&(ch>='A')) {
    ch+=32;
    count+=1;
    }
    else if((ch<='z')&&(ch>='a')){
    ch-=32;
    count+=1;
    }
    System.out.println("The convert char is: "+ch);
    }
    }while(ch!='.');
    System.out.println("The numbers of convert is: "+count);
    }
    }在你的第二个if的前面要加上else,否则经过第一个if处理后,ch又满足第二个if的条件了。