これは非常に基本的な Java の質問であり、回答を得た後は自分自身を叩くように感じますが、現在プロジェクトに取り組んでおり、このメソッドを追加するよう指示されています: +createWelcomeMessage(userName:String) というメソッドを作成します。 )String[これも下線が引かれているので静的]. ユーザーが入力した名前を含め、プログラムの目的をユーザーに知らせる必要があります。これは私が得たものです:
public static String createWelcomeMessage(String UserName)
{
Scanner kb = new Scanner(System.in);
String strUserName; // to get user's name
String strWelcome; //listed as the return in method name
System.out.print("\nPlease enter your name: ");
strUserName=kb.nextLine();
System.out.println("Hello" + strUserName + " the purpose of this project is...");
return strWelcome;
} //end createWelcomeMessage(string)
問題は、文字列 "strWelcome" をどうするかということです。それとも、このメソッドを呼び出すためにメインメソッドで使用するだけですか。ありがとう。