1 public class ConverTo 2 3 { public static void main(String [] args) 4 { String numberIn =args[0]; 5 convertNum(numberIn); 6 } 7 static void convertNum(String num) 8 { 9 long showNumber; 10 String temp; 11 switch(num) 12 { case "one": 13 temp = "1"; 14 showNumber = Long.parseLong(temp); 15 System.out.println(num+"convert to"+showNumber); 16 break; 17 case "two": 18 temp = "2"; 19 showNumber = Long.parseLong(temp); 20 System.out.println(num+"convert to"+showNumber); 21 break; 22 case "three": 23 temp ="3"; 24 showNumber = Long.parseLong(temp); 25 System.out.println(num+"convert to"+showNumber); 26 break; 27 case "four": 28 temp = "4"; 29 showNumber = Long.parseLong(temp); 30 System.out.println(num+"convert to"+showNumber); 31 break; 32 case "five": 33 temp = "5"; 34 showNumber = Long.parseLong(temp); 35 System.out.println(num+"convert to"+showNumber); 36 break; 37 case "six": 38 temp = "6"; 39 showNumber = Long.parseLong(temp); 40 System.out.println(num+"convert to"+showNumber); 41 break; 42 case "seven": 43 temp = "7"; 44 showNumber = Long.parseLong(temp); 45 System.out.println(num+"convert to"+showNumber); 46 break; 47 case "eight": 48 temp = "8"; 49 showNumber = Long.parseLong(temp); 50 System.out.println(num+"convert to"+showNumber); 51 break; 52 case "nine": 53 temp = "9"; 54 showNumber = Long.parseLong(temp); 55 System.out.println(num+"convert to"+showNumber); 56 break; 57 case "ten": 58 temp = "10"; 59 showNumber = Long.parseLong(temp); 60 System.out.println(num+"convert to"+showNumber); 61 break; 62 63 } 64 65 } 66 67 }
Long.parseLong(String s) 其中s必须是数字形式的字符串,才能运用该函数转化为长整型。