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,
1190 Reverses the substring between each pair of parentheses leetcodemysql Joint index details You don't know ——HarmonyOS Create data mysql Library process Character recognition technology of vehicle license plate based on Neural Network A guess number of small games , use JavaScript realization Talking about uni-app Page value transfer problem pytorch of ResNet18( Yes cifar10 The accuracy of data classification is achieved 94%)C++ Method of detecting memory leak One is called “ Asking for the train ” A small village Finally got the train