使用している Do/While ループに問題があります。ユーザーが入力する文字または文字列に関係なく、while 条件が満たされない場合でも、if ブロックが表示されます。
より具体的には、このコードは条件 (スコアを計算しますか?) を与え、ユーザーの応答に基づいて if ブロック (user = y ---> What is your name など) を続行することを意図しています。 which ステートメントが満たされない場合は、スキップします (ユーザー = n ----> プログラムが終了します)。
私が使用したコードは以下のとおりです。
このコードは完成しておらず、表示されている一部の変数はまだ使用されていないことに注意してください。
import java.util.Scanner;
public class Test1 {
public static void main (String [] args) {
//Declares letters to allow repetition of program
final String START= "y";
//Declerations of variables
//Declares space for user's name
String Name;
//Declares space for user's year of birth
int Year;
//Declares space for user's double value, day and month of birth entered
//by user
double birthDM;
//Declares space for int value day of birth, calculated from double value
int day;
//Declares space for int value month of birth, calculated from double value
int month;
//Declares space for int of calculated score
int Score = 0;
//Declares space for the string value of test (check wording)
String confirmation;
//Declares space for total number of scores calculated
int Total;
//Initilisaton of Scanner object
Scanner sc;
//Declares the space for the string that will carry the initilising letter
String userStart;
//Declares space for the char that will activate program
char yesChar;
// Program Start
//User input to begin loop or not (test)
System.out.println(
"The following program will calculate an score from your name and birthday.");
System.out.println(" ");
do {
System.out.println("Would you like to calculate and score?");
sc = new Scanner(System.in);
userStart=sc.next();
if (uProgStart.equalsIgnoreCase(PROGSTART));
{
System.out.println("What is your name?");
userName=sc.next();
System.out.println("What is the year of your birth?");
birthYear = sc.nextInt();
}
} while(!uProgStart.equalsIgnoreCase(PROGSTART));
System.out.println("Program End");
}
}
ありとあらゆる助けをいただければ幸いです。