我開始學習本週早些時候(星期一)java和現在,而只是通過excercises打算從http://programmingbydoing.com/ (具體鍛鍊; Tibial我做的是http://programmingbydoing.com/a/a-little-quiz.html)找不到符號。 java編譯器錯誤
,現在我碰到一個錯誤我似乎無法修復。
import java.util.Scanner;
public class Quiz
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
String ready,answer3;
int answer1,answer2, score;
score = 0;
System.out.println ("Are you ready for a quis?(Y/N) ");
ready = keyboard.next();
if (ready == Y)
{
System.out.println ("Great, let's get to it then!");
}
else if (ready == N)
{
System.out.println ("Well since you did start this program of your own volition I assume you are ready and you're simply having a go at me.");
}
else
{
System.out.println ("Error, wrong input!");
}
System.out.println();
System.out.println ("Q1) What is the capital of Australia?");
System.out.println (" 1) Brisbane");
System.out.println (" 2) Sydney");
System.out.println (" 3) Canberra");
answer1 = keyboard.nextInt();
if (answer1 == 1)
{
System.out.println ("Sorry, Canberra is the capital of Australia");
}
else if (answer1 == 2)
{
System.out.println ("Sorry, Canberra is the capital of Australia");
}
else if (answer1 == 3)
{
System.out.println ("Correct!");
score = score+1;
}
else
{
System.out.println ("Error, wrong input!");
}
System.out.println();
System.out.println ("Q2) Can you store the value 'cat' in a varible of the int type? ");
System.out.println (" 1) Yes");
System.out.println (" 2) No");
answer2 = next.keyboardInt();
System.out.println();
if (answer2 == 1)
{
System.out.println ("Sorry, 'cat' is a string, ints can only store numbers.");
}
else if (answer2 == 2)
{
System.out.println ("That's right!");
score = score+1;
}
else
{
System.out.println("Error, wrong input");
}
System.out.println();
System.out.println ("Did vikings wear horned helmets in combat?(Y/N)");
System.out.println (" 1) Yes");
System.out.println (" 2) No");
answer3= keyboard.next();
System.out.println();
if (answer3 == Y)
{
System.out.print (" That's wrong, the only times a viking would ever have..... nevermind let's proceed with the quiz");
}
else if (answer3 == N)
{
System.out.println ("Correct!");
score = score+1;
}
else
{
System.out.println ("Error, wrong input!");
}
System.out.println ("Overall, you got a total score of " + score + " out of 3 possible.");
System.out.println ("Thanks for playing");
}
}
我很感謝任何人都可以提供的幫助!
請提供實際的錯誤代碼。 – 2014-08-28 12:59:38
什麼是錯誤? – 2014-08-28 13:02:15