public class キャスト {Output:
public static voidmain(文字列[] args) {
文字列 nbs = "12";
int nb;
nb = new Integer(nbs);
System.out.println(nb);
}
}
12
public class Cast {Output:
public static void main(String[] args) {
String nbs = "12";
int nb;
nb = new Integer(nbs);
System.out.println(nb);
}
}
12
public class Cast {Output:
public static void main(String[] args) {
String nbs = "12";
int nb;
nb = Integer.parseInt(nbs);
System.out.println(nb);
}
}
12
public class Cast {出力:
public static void main(String[] args) {
String nbs = "12.4s";
int nb;
System.out.println(stringToInt(nbs,0));
}
public static int stringToInt(String value, int _default) {
{
return Integer.parseInt(value);
} catch (NumberFormatException e) {
return _default;
}
}
}
0変数 nbs が数値でない場合、関数 stringToInt() はデフォルトで 0 を返します。
Please disable your ad blocker and refresh the window to use this website.