私の先生は私にこの質問をしました:
次のことを行うプログラムを作成します。
- あなたの名を入力してください:ピーター
- 家系の名前を入力してください:Opunga
- 生年月日を入力してください:1992
- こんにちはピーターオプンガ、あなたは今年の終わりまでに20歳になります。
- ボーナス1:適切なコメント。(10%)
- ボーナス2:プログラム全体で2つの文字列のみを作成します。(10%)
- ボーナス3:正確に4つのSystem.out.printを使用します。(10%)
今、私はJavaに完全に慣れていません。私はちょうど一週間前にそれを紹介されました、そしてこれは私が思いついたものです:
import java.io.*;
public class A1Chuah {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader (new InputStreamReader (System.in));
//Prints instructions for user to enter first name.
System.out.println("Enter first name: ");
//Obtains user input for first name.
String first = in.readLine ();
//Prints instructions for user to enter last name.
System.out.print ("Enter last name: ");
//Obtains user input for last name.
String last = in.readLine();
//Prints instructions for user to enter birth year.
System.out.print ("Enter your birth year: ");
//Obtains user input for birth year.
String year = in.readLine ();
//Converts String year to int useryr
int useryr = Integer.parseInt(year);
//Sets int oriyr to value of 2012
int oriyr = 2012;
//Sets int outyr as oriyr - useryr
int outyr = oriyr - useryr;
//Prints out information.
System.out.println("Hi" + " " + " " + last + "," + " " + "you will be" + " " + outyr + " " + "by the end of this year");
ボーナス1と3をなんとか完了しましたが、ボーナス2を理解できないようです。助けてください!PS彼は、私が自分の考えとしてそれを伝えようとしない限り、私は助けを得ることができると言いました。