问题描述
这是部分代码,求高手解下Stringa[]=newString[1000];Stringupper="";Stringlower="";Stringt="";InputStreamReaderir;BufferedReaderin;try{ir=newInputStreamReader(System.in);in=newBufferedReader(ir);System.out.println("请输入字符串,'quit'toquit");for(inti=0;i<1000;i++){a[i]=in.readLine();for(intindex=0;index<a[i].length();index++){charc=a[i].charAt(index);if((c>'A'-1)&&(c<'Z'+1)){upper+=c;t=upper.toLowerCase();}elseif((c>'a'-1)&&(c<'z'+1)){lower+=c;t=lower.toUpperCase();}elseif((c>47)&&(c<58)){t="0";}else{t="#";}}if(a[i].equals("quit")){break;}}}catch(IOExceptione){System.out.println("error!");}System.out.println("转换后的字符串"+t);
解决方案
解决方案二:
按原来的输出什么意思?举个例子吧
解决方案三:
给你我写的大小写转换代码看看importjava.lang.Character;publicclassTest{publicstaticvoidmain(String[]args){char[]temp;Stringstr="AbCdEfGh";temp=str.toCharArray();for(inti=0;i<temp.length;i++){if(Character.isLetter(temp[i])){if(Character.isLowerCase(temp[i])){temp[i]=Character.toUpperCase(temp[i]);}else{temp[i]=Character.toLowerCase(temp[i]);}}}str=newString(temp);System.out.println(str);}}
解决方案四:
字符串要从键盘输入
解决方案五:
importjava.lang.Character;importjava.io.*;publicclassTest{publicstaticvoidmain(String[]args){char[]temp;//Stringstr="AbCdEfGh";Stringstr="";InputStreamReaderir;BufferedReaderin;try{ir=newInputStreamReader(System.in);in=newBufferedReader(ir);System.out.println("请输入字符串,'quit'toquit");str=in.readLine();}catch(IOExceptione){System.out.println("error!");}temp=str.toCharArray();for(inti=0;i<temp.length;i++){if(Character.isLetter(temp[i])){if(Character.isLowerCase(temp[i])){temp[i]=Character.toUpperCase(temp[i]);}else{temp[i]=Character.toLowerCase(temp[i]);}}}str=newString(temp);System.out.println(str);}}