change_letter.java package test;import java.util.Scanner;public class change_letter { public static String Upper(String str){ String result = ""; for(int i = 0 ; i str.length(); i++){ int begin = (int)str.charAt(i) - 32; if(begin=65 begin=9
package test; import java.util.Scanner; public class change_letter { public static String Upper(String str){ String result = ""; for(int i = 0 ; i < str.length(); i++){ int begin = (int)str.charAt(i) - 32; if(begin>=65 && begin<=90){ char end = (char)begin; result = result + end; } else { char end = (char)(begin+32); result = result + end; } } return result; } public static String Lower(String str){ String result = ""; for(int i = 0 ; i < str.length(); i++) { int begin = (int) str.charAt(i) + 32; if (begin >= 97 && begin <= 122) { char end = (char) begin; result = result + end; } else{ char end = (char) (begin-32); result = result + end; } } return result; } public static void main(String[] args) { System.out.print("请输入字符串 : "); Scanner sr = new Scanner(System.in); String str = sr.next(); System.out.println("输入的字符串为:"+str); System.out.println("字符串全变为大写为 :"+ Upper(str)); System.out.println("字符串全变为小写为 :"+Lower(str)); } }