package com.itranswarp.learnjava;
/**
* Learn Java from https://www.liaoxuefeng.com/
*
* @author liaoxuefeng
*/
public class Main {
public static void main(String[] args) {
String a = "12";
String b = "x9";
// TODO: 捕获异常并处理
int c = stringToInt(a);
int d = stringToInt(b);
System.out.println(c * d);
}
static int stringToInt(String s) {
try {
//用指定编码转换String为Int:
return Integer.parseInt(s);
catch (NumberFormatException e) {
System.out.println("Something wrong with your input number");
return 0;
Sign in to make a reply
牛油火锅不错
package com.itranswarp.learnjava;
/**
* Learn Java from https://www.liaoxuefeng.com/
*
* @author liaoxuefeng
*/
public class Main {
public static void main(String[] args) {
String a = "12";
String b = "x9";
// TODO: 捕获异常并处理
int c = stringToInt(a);
int d = stringToInt(b);
System.out.println(c * d);
}
static int stringToInt(String s) {
try {
//用指定编码转换String为Int:
return Integer.parseInt(s);
}
catch (NumberFormatException e) {
}
System.out.println("Something wrong with your input number");
return 0;
}
}