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,
802.11 CCA and NAV mechanism docker Where is the image stored Software engineering career planning RISC-V_GD32VF103-TIMER0 timer interrupt Create a thread ——— Javaweb (3)MySQL The golden rule of :“ Do not use SELECT ”MYSQL database SQL Sentence practice experiment EXERCISES. 1 SIMPLE COMMANDSMySQL Basics Commonly used sentence ( Add / delete / modify query )pandas Multiply two columns in use Java Write a simple student management system