Discuss / Java / 练习

练习

Topic source

Kerio

#1 Created at ... [Delete] [Delete and Lock User]
public class Main {

    public static void main(String[] args) {
        String a = "12";        
        String b = "X9";        
        // TODO: 捕获异常并处理        
        int c = 0;        
        int d = 0;        
        try {
            c = stringToInt(a);            
            d = stringToInt(b);            
            System.out.println(c * d);        
          } catch (NumberFormatException e ) {
            e.printStackTrace();        
          } finally {
            System.out.println("END!");        
          }
      }

    static int stringToInt(String s) {
       return Integer.parseInt(s);    
    }
}

  • 1

Reply