返回列表 發帖
本帖最後由 鍾易澄 於 2023-6-10 11:38 編輯
  1. import java.util.Scanner;

  2. public class Ch01 {

  3.         public static void main(String[] args) {

  4.                 Scanner sc = new Scanner(System.in);
  5.                 String input = sc.next();
  6.                 sc.close();               
  7.                 int pass=1;
  8.                                     
  9.                 int first = input.charAt(0);   
  10.                 if (input.length() == 1) {
  11.                                     
  12.                   
  13.                                         if(first>=48 && first<=57)
  14.                                         {
  15.                                                
  16.                         first++;      
  17.                         if(first==58)
  18.                                                 {
  19.                                                      
  20.                                                         first=48;        
  21.                                                 }
  22.                            
  23.                     }
  24.                                        
  25.                                         else if(first>=65 && first<=90)
  26.                                         {
  27.                                                
  28.                                                 first+=33;
  29.                                         }        
  30.                     else if(first>=97 && first<=122)
  31.                                         {      
  32.                                                 
  33.                         first-=31;
  34.                                         }                    
  35.                                         else
  36.                                         {
  37.                         pass=0;
  38.                                         }
  39.                                         if(pass==1)
  40.                                         {
  41.                                                
  42.                         System.out.println((char)first);      
  43.                     }
  44.                                         else
  45.                                         {
  46.                                                
  47.                                                 System.out.println("error");
  48.                                         }
  49.                                 
  50.                 }
  51.                                 else{
  52.                                        
  53.                                         if(first>=48 && first<=57)
  54.                                         {
  55.                                                
  56.                         first++;      
  57.                         if(first==58)
  58.                                                 {
  59.                                                         
  60.                                                         first=48;      
  61.                                                 }
  62.                            
  63.                     }
  64.                                     
  65.                                         else if(first>=65 && first<=90)
  66.                                         {
  67.                                                
  68.                                                 first+=33;
  69.                                         }        
  70.                     else if(first>=97 && first<=122)
  71.                                         {      
  72.                                                
  73.                         first-=31;
  74.                                         }                    
  75.                                         else
  76.                                         {
  77.                         pass=0;
  78.                                         }
  79.                                         int last = input.charAt(input.length()-1);      
  80.                     if(last>=48 && last<=57){
  81.                         last++;
  82.                         if(last==58)
  83.                             last=48;
  84.                     }
  85.                                         else if(last>=65 && last<=90)
  86.                         last+=33;
  87.                     else if(last>=97 && last<=122)
  88.                         last-=31;
  89.                     else
  90.                         pass=0;
  91.                     if(pass==1)
  92.                                              
  93.                         System.out.println((char)first+input.substring(1, input.length()-1)+(char)last);
  94.                     else
  95.                         System.out.println("error");
  96.                 }
  97.         }
  98. }
複製代碼

TOP

返回列表