Tips : use for loop , String “HelloWorld” Traverse from the last character , When the traversal character is uppercase , Need to be converted to lowercase ; Otherwise, it is converted to upper case . Define a StringBuffer object , call append() Method to add the traversal characters in turn , Last call StringBuffer Object's toString() method , And output the result .
public class Reverse { public static void main(String[] args) { // TODO
Auto-generated method stub String str="HelloWorld"; char[]
str1=str.toCharArray(); StringBuffer buf = new StringBuffer(str.length()); /* *
Method 1 * */ /* for(int i=str1.length-1;i>=0;i--) { if(str.charAt(i) ==
str.toLowerCase().charAt(i)){ //charAt() Method to return the char value . Determine case
buf.append(str.toUpperCase().charAt(i)); }else{
buf.append(str.toLowerCase().charAt(i)); } } System.out.print(buf.toString());
*/ /* * Method 2 * adopt ASCII Code to determine the case of letters ASCII stay 65-90 In between are capitals ,97-122 It's lowercase * Large to small 32 Small to large minus 32 * */
for(int i=str1.length-1;i>=0;i--) { // If ASCII stay 65-90 Capitalized between , add 32 lower case
if((int)str1[i]>=65 && (int)str1[i]<=90) { buf.append((char)((int)str1[i]+32));
// If ASCII stay 97-122 Lower case between , subtract 32 Capitalize }else if((int)str1[i]>=97 && (int)str1[i]<=122){
buf.append((char)((int)str1[i]-32)); } } System.out.print(buf.toString()); } }
 

Technology
©2019-2020 Toolsou All rights reserved,
c Language implementation 《 Student management system 》 No hole is the future of mobile phone ? There are still many problems to be solved Junior , A little sense , Just for mutual encouragement How to use Vue Used in Echarts Visual Library The 11th Blue Bridge Cup Java The second provincial competition B Group part Python- be based on OpenCV Contour fill for flooding algorithm hole filling 【C#】 The realization of student achievement information management system List Common interview questions in the collection and simple ideas China Mobile Science Popularization : Why do mobile networks call “ Cellular mobile network ”【Golang Basic series 10 】Go language On conditional sentences if