String(birthyear) を int(age) に変換するのに問題があります。誰かに生年月日を入力してもらい、プログラムに簡単な減算計算をさせて年齢を計算してもらいたい。私はプログラミングが初めてなので、いろいろ調べてみましたが、ほとんどの場所で同じことが言われました。
Integer.parseInt(birthyear);
しかし、それをして、計算しようとすると...
int age = year-birthyear;
タイトルにエラーが表示されます。
public class WordGameScanner
{
public static void main(String[] argus)
{
String name;
String home;
String birthyear;
String course;
String reason;
String feedback;
int year = 2013;
Scanner input = new Scanner(System.in);
System.out.print("What is your name: ");
name = input.nextLine();
System.out.print("Where are you from: ");
home = input.nextLine();
System.out.print("What year were you born: ");
birthyear = input.nextLine();
Integer.parseInt(birthyear);
System.out.print("What are you studying: ");
course = input.nextLine();
System.out.print("Why are you studying " + course + ": ");
reason = input.nextLine();
System.out.print("How is " + course + " coming along so far: ");
feedback = input.nextLine();
int age = year-birthyear;
System.out.println("There once was a person named " + name +
" who came all the way from " + home +
" to study for the " + course +
" degree at --------------.\n\n" + name +
" was born in " + birthyear + " and so will turn " + age +
" this year.");
System.out.println(name + " decided to study the unit ------------, because \"" +
reason + "\". So far, ----------- is turning out to be " +
feedback + ".");
}
}
これが間違った場所にある場合は申し訳ありませんが、これはここでの私の2番目の投稿です。「質問する」をクリックして、指示に従いました >.<