This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
char s[]=scn.nextLine().toCharArray(); | |
for(int i=s.length-1;i>=0;i--){ | |
if(s[i]>64&&s[i]<91) | |
System.out.printf("%c",s[i]+32); | |
else if(s[i]>96&&s[i]<123) | |
System.out.printf("%c",s[i]-32); | |
else | |
System.out.print(s[i]); | |
} | |
System.out.println(); | |
} | |
/*題目:C_ST22-易 迴文字串 II | |
作者:1010 | |
時間:西元 2017 年 4 月*/ | |
} |
我第一種寫法是利用字串去實作並利用toCharArray然後在利用字串toUpperCase、toLowerCase系統竟然回傳值1
所以最後只好乖乖地用成字串陣列依序判斷翻轉,那一樣也是利用ASCII碼判斷大小寫
A~Z是65~90
a~z是97~122
沒有留言:
張貼留言