小白求教,刚接触java求解决

QWERTsdfghjWERTYUIsdfghjWERTYUI
请通过代码,必须使用循环和数组转换以上文字的大小写

字符串 的toUpperCase() 方法直接搞定了,

大写转小写
 char[] queue = str.toCharArray();
for (int index = 0; index < queue.length; index++) {
  if (((int) queue[index] > 96) && ((int) queue[index] < 123)) {
    queue[index] = (char) ((int) queue[index] - 32);
  }
}
System.out.println("Upper: " + String.valueOf(queue));

小写转大写
char[] queue = str.toCharArray();
for (int index = 0; index < queue.length; index++) {
  if (((int) queue[index] > 64) && ((int) queue[index] < 91)) {
    queue[index] = (char) ((int) queue[index] + 32);
  }
}
System.out.println("Lower: " + String.valueOf(queue));


public class CaseConverter {

public static void main(String[] args) {
    String str = "QWERTsdfghjWERTYUIsdfghjWERTYUI";
    System.out.println(convertCase(str));
}

public static String convertCase(String srcStr){
    char[] chars = srcStr.toCharArray();
    StringBuffer strBuffer = new StringBuffer();
    for(int i = 0; i < chars.length; i++){
        if(chars[i] >= 65 && chars[i] <= 90){
            chars[i]=(char) (chars[i]+32);
            strBuffer.append(chars[i]);
        }
        else if(chars[i] >= 97 && chars[i] <= 122){
            chars[i]=(char) (chars[i]-32);
            strBuffer.append(chars[i]);
        }
    }
    return strBuffer.toString();
}

}

String str = "QWERTsdfghjWERTYUIsdfghjWERTYUI";
        char []arry = str.toCharArray();
        for (int i = 0; i < arry.length; i++) {
            if(arry[i]>=65 && arry[i]<=90){
                arry[i]+=32;
            }else if(arry[i]>=97 && arry[i]<=122){
                arry[i]-=32;
            }
        }

你是想所有小写转换成大写,所有大写转成小写,还是把所有的都转换成大写或者小写

 public class Test {
    public static void main(String args[]){
        String ss="FSFdgdgFSDF";
        String newss="";
        char[]array=ss.toCharArray();
        for(char s:array){
            if(Character.isLowerCase(s)){
                newss+=Character.toUpperCase(s);
            }else if(Character.isUpperCase(s)){
                newss+=Character.toLowerCase(s);
            }
        }
        System.out.println(newss);
    }
}

我觉得你应该是想把大写转小写 小写转大写 如果是这样的话 你可以这么写

public class Test {
public static void main(String args[]){
String ss="FSFdgdgFSDF";
String newss="";
char[]array=ss.toCharArray();
for(char s:array){
if(Character.isLowerCase(s)){
newss+=Character.toUpperCase(s);
}else if(Character.isUpperCase(s)){
newss+=Character.toLowerCase(s);
}
}
System.out.println(newss);
}
}