- 此问题在此处已有答案**:
(23个答案)
2天前关闭。
我对java有些陌生。这基本上是一个测验,告诉你当你完成时你是什么十六进制代码。现在,我只是在计算点,稍后将转换它们,现在,每个点的值是1。但是当我打印它们时,它们要存储的变量出现为零。
是的,我正在控制台中输入y。我猜这要么与我第一次在代码中存储变量的位置有关,要么与扫描仪有关。
import org.apache.commons.lang3.ArrayUtils;
import java.util.Arrays;
public class javaQuiz{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[][] allQuest = {{"Would you describe yourself as hotheaded?", "Do you like spicy foods?", "Are you an extrovert?"},
{"Do you like nature?", "Do you read a lot of books?", "Do you get jealous easily?"},
{"Do you like the ocean?", "Do you like soccer?", "Are you a sensitive person?"}}; //make sure these all have an equal # or it won't work
int fullLength = allQuest.length * allQuest[1].length;
String newQuest = "jkskiaka";
int redPts = 0;
int greenPts = 0;
int bluePts = 0;
String[] hexSingValues = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
int questRow = 0;
int questColumn = 0;
System.out.println("Answer y or n");
for (int i = 0; i < fullLength; i++){
newQuest = allQuest[questColumn][questRow++];
if (questRow > allQuest[1].length - 1){
questRow = 0;
questColumn++;
}
System.out.println(newQuest);
String answer = scanner.nextLine();
/* point system starts here */
if (answer == "y"){
if (questColumn == 1){
redPts++;
}
if (questColumn == 2){
greenPts++;
} if (questColumn == 3){
bluePts++;
} //value of 1 may change
} else{
continue;
}
}
System.out.println(redPts + ", " + greenPts + ", " + bluePts);
}
}```
1条答案
按热度按时间s5a0g9ez1#
对于字符串,应该使用.equals()而不是==操作符。==操作符检查引用是否相等,这意味着它检查两个对象在内存中是否是同一个对象。
您应该使用以下命令:
这将确保比较基于String的实际值,而不是其引用。
我修复了你的错误,你可以试试这个: