Newer
Older
Java / practice / HowOldAreYou.java
import java.io. *;

public class HowOldAreYou {
  public static void main(String[] args){
    System.out.println("あなたの名前を入力:");
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    try{
      String line = reader.readLine();
      System.out.println(line + "さん。こんにちは。");
      System.out.println("年齢を入力してください。");
      line = reader.readLine();
      int age = Integer.parseInt(line);
    System.out.println("あなたは" + age + "歳ですか。5年後は" + (age + 5) + "歳ですね。");
    }catch (IOException e) {
      System.out.println(e);
    }catch (NumberFormatException e){
      System.out.println("年齢が正しくありません。");
    }
  }
}