「java入門」java.lang.NumberFormatExceptionのサンプル

2018年8月25日

サンプルコード
package com.arkgame.study;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class NumberFormatDemo {

public static void main(String[] args) throws IOException {
BufferedReader sysr = new BufferedReader(new InputStreamReader(System.in));

System.out.print(“enter number:");
String cft = sysr.readLine();
System.out.println(“num= " + cft);

try {
int n = Integer.parseInt(cft);
System.out.println(“num * 5 = " + (n * 5));
} catch (NumberFormatException e) {
System.out.println(cft + “は数字ではない");
}

}
}

Java

Posted by arkgame