#2446: 如何判斷是否輸入英文?


a94bjo4dk4 (Mission 6)

學校 : 國防大學
編號 : 7545
來源 : [140.129.96.59]
最後登入時間 :
2010-05-03 16:19:34
d086. 態度之重要的證明 -- 成功電研20th~21st C++ ~最後的競賽~ | From: [140.129.98.133] | 發表日期 : 2009-10-07 23:24

import java.util.Scanner;//.toLowerCase() //                 try{       }catch(NumberFormatException e)     input >= 'A' && input <= 'Z')
public class d086 {
  static String A[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
  static int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26};
 public static void main(String[] args){
  Scanner input=new Scanner(System.in);
  while(input.hasNext()){
    String word="";
    word+=input.nextLine();
    if(word.equals("0")){
     break;
    }else{
     int grade=0;   
     for(int j=0;j<word.length();j++){
      for(int i=0;i<a.length;i++){
       if(String.valueOf(word.charAt(j)).equalsIgnoreCase(A[i]))
        grade+=a[i];
      }
     }
     System.out.println(grade);
    }

  }
 }
}

想寫成不是輸入英文和"0"輸出"fail"

 
ZeroJudge Forum