2016年7月12日 星期二

ITSA 42 [Problem2] 迴文字串


http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=25960

import java.util.*;

public class Main {

 public static void main(String[] args) {
  Scanner scn = new Scanner(System.in);
  int n = scn.nextInt(), tot;
  for (int i = 0; i < n; i++) {
   String str = scn.next();
   char arr[] = str.toCharArray();
   for (int j = arr.length - 1; j >= 0; j--) {
    tot = arr[j];
    if (arr[j] >= 'A' && arr[j] <= 'Z') {
     tot = Character.toLowerCase(arr[j]);
    }
    if (arr[j] >= 'a' && arr[j] <= 'z') {
     tot = Character.toUpperCase(arr[j]);
    }
    System.out.printf("%c", tot);
   }
   System.out.println();
  }
 }
/* 
    題目:[Problem2] 迴文字串
    作者:1010
    時間:西元 2016 年 7 月 */

}




public class Main{
 public static void main(String [] argv){
  //非字母的字元不會做任何改變
  String str = "abcd+ef123";
  //轉換成大寫
  System.out.println(str.toUpperCase());
  //轉換成小寫
  System.out.println(str.toLowerCase());
 }
 /* 
    題目:字串轉大小寫
    作者:1010
    時間:西元 2016 年 7 月 */
}


import java.lang.Character;

public class Main{
 public static void main(String [] argv){
  //非字母的字元不會做任何改變
  char ch = 'a';
  //轉換成大寫
  System.out.println(Character.toUpperCase(ch));
  //轉換成小寫
  System.out.println(Character.toLowerCase(ch));
 }

 /* 
    題目:字元轉大小寫
    作者:1010
    時間:西元 2016 年 7 月 */
}


沒有留言:

張貼留言