Discuss / Java / 作业,已验证。

作业,已验证。

Topic source

Nobody52297

#1 Created at ... [Delete] [Delete and Lock User]

package com.itranswarp.learnjava;

import java.lang.NumberFormatException;

public class Main {

public static void main(String[] args) {

String a = "12";

String b = "x9";

// TODO: 捕获异常并处理

try {

int c = stringToInt(a);

int d = stringToInt(b);

System.out.println(c * d);

}catch(NumberFormatException e){

System.out.println(e);

}

}

static int stringToInt(String s) throws NumberFormatException{

return Integer.parseInt(s);

}

}

卡酷0837

#2 Created at ... [Delete] [Delete and Lock User]

public static void main(String[] args) {

String a = "12";

String b = "x9";

// TODO: 捕获异常并处理

try {

int c = stringToInt(a);

int d = stringToInt(b);

}catch(Exception e) {

System.out.println(e);

}}

static int stringToInt(String s) {

return Integer.parseInt(s);

}

我这个和你这个一个意思吧


  • 1

Reply