割り当て用の単純なコンソールアプレットを作成していますが、アプリを実行しようとするとエラーが発生しました。エラーは次のとおりです。
'型の不一致:voidからStringに変換できません'。
'ElseIf'ステートメントが繰り返し発生するため、エラーが4回発生します。
問題が発生する要素は次のとおりです。
String thirdNum = println("Would you like a third number?(Y/N)");
完全なコードは次のとおりです。
import acm.program.*;
public class abacusConsole extends ConsoleProgram {
public void run() {
println("This program is a basic calculator two numbers!");
println("Operations that the program recognises: \n Add \n Subtract \n Multiply \n Divide");
String operator = readLine("Which operator would you like to use?");
if (operator.equals("Add")) {
int n1 = readInt("First Number");
int n2 = readInt("Second Number");
String thirdNum = println("Would you like a third number?(Y/N)");
if (thirdNum.equals("Y")) {
int n3 = readInt("Third Number:");
int total = n1 + n2 + n3;
println(+n1+" + "+n2+" + "+n3+" = "+total+".");
} else if (thirdNum.equals("N")) {
int total = n1 + n2;
println(+n1+" + "+n2+" = "+total+".");
} else {
println("Please reload the application and type in either 'Y' or 'N'");
}
} else if (operator.equals("Subtract")) {
int n1 = readInt("First Number");
int n2 = readInt("Second Number");
String thirdNum = println("Would you like a third number?(Y/N)");
if (thirdNum.equals("Y")) {
int n3 = readInt("Third Number:");
int total = n1 - n2 - n3;
println(+n1+" - "+n2+" - "+n3+" = "+total+".");
} else if (thirdNum.equals("N")) {
int total = n1 + n2;
println(+n1+" - "+n2+" = "+total+".");
} else {
println("Please reload the application and type in either 'Y' or 'N'");
}
} else if (operator.equals("Multiply")) {
int n1 = readInt("First Number");
int n2 = readInt("Second Number");
String thirdNum = println("Would you like a third number?(Y/N)");
if (thirdNum.equals("Y")) {
int n3 = readInt("Third Number:");
int total = n1 * n2 * n3;
println(+n1+" x "+n2+" x "+n3+" = "+total+".");
} else if (thirdNum.equals("N")) {
int total = n1 * n2;
println(+n1+" x "+n2+" = "+total+".");
} else {
println("Please reload the application and type in either 'Y' or 'N'");
}
} else if (operator.equals("Divide")) {
int n1 = readInt("First Number");
int n2 = readInt("Second Number");
String thirdNum = println("Would you like a third number?(Y/N)");
if (thirdNum.equals("Y")) {
int n3 = readInt("Third Number:");
int total = n1 / n2 / n3;
println(+n1+" / "+n2+" / "+n3+" = "+total+".");
} else if (thirdNum.equals("N")) {
int total = n1 / n2;
println(+n1+" / "+n2+" = "+total+".");
} else {
println("Please reload the application and type in either 'Y' or 'N'");
}
}
}
}