标签:i++ ann char 文字 can 连续 character style 字母
1 import java.util.Scanner; 2 3 4 public class Main { 5 6 public static void main(String[] args) { 7 // TODO Auto-generated method stub 8 Scanner input = new Scanner(System.in); 9 int n=input.nextInt(); 10 String s =input.next(); 11 char[] a=s.toCharArray(); 12 switch (n) { 13 case 1: 14 s=s.toUpperCase(); 15 System.out.println(s); 16 break; 17 case 2: 18 s=s.toLowerCase(); 19 System.out.println(s); 20 break; 21 case 3: 22 for(int i=0;i<s.length()/2;i++) 23 { 24 int j=s.length()-i-1; 25 char c=a[i]; 26 a[i]=a[j]; 27 a[j]=c; 28 j--; 29 } 30 s=String.valueOf(a); 31 System.out.println(s); 32 break; 33 case 4: 34 for(int i=0;i<s.length();i++) 35 { 36 char c= s.charAt(i); 37 if(Character.isUpperCase(c)) 38 { 39 a[i]=Character.toLowerCase(c); 40 } 41 else 42 a[i]=Character.toUpperCase(c); 43 } 44 s=String.valueOf(a); 45 System.out.println(s); 46 break; 47 case 5: 48 s=s.toLowerCase(); 49 a=s.toCharArray(); 50 int count=0; 51 52 System.out.print(a[0]); 53 for(int i=1;i<s.length();i++) 54 { 55 56 while(a[i]-a[i-1]==1) 57 { 58 count++; 59 i++; 60 if(i>=s.length()) 61 break; 62 } 63 if(count>1) 64 { 65 System.out.print("-"+a[--i]); 66 } 67 else 68 { 69 if(count>0) 70 i--; 71 System.out.print(a[i]); 72 } 73 count=0; 74 } 75 break; 76 default: 77 break; 78 } 79 80 81 } 82 83 84 85 }
标签:i++ ann char 文字 can 连续 character style 字母
原文地址:http://www.cnblogs.com/fjl-vxee/p/6650747.html