java - Why do I get "cannot find symbol" using scanner when compiling? -
i'm learning java here, wrote simple program, error every time try compile it. error get:
trivia.java:14: error: cannot find symbol ret = sc.nextline(); ^ the program follows:
import java.util.scanner; class gamestart { public static void main(string[] args){ scanner sc = new scanner(system.in); string ret; byte qnum; string ans; string correct = "awesomely correct!"; string wrong = "darn it! got it!"; system.out.println("do think know stuff?"); ret = sc.nextline; if (ret.equals("yes") || ret.equals("yes")) { system.out.println("well, let's test know! choose number 1 5!"); qnum = sc.nextbyte(); switch (qnum) { case 1: system.out.println("in year did french revolution start?"); ans = sc.nextline(); if (ans.equals("1789") || ans.equals("seventeen eighty nine")) { system.out.println(correct); } else { system.out.println(wrong); } break; case 2: system.out.println("how many protons sodium atom have?"); ans = sc.nextline(); if (ans.equals("11") || ans.equals("eleven")) { system.out.println(correct); } else { system.out.println(wrong); } break; case 3: system.out.println("what 2^6*0.5-12?"); ans = sc.nextline(); if (ans.equals("20") || ans.equals("twenty")) { system.out.println(correct); } else { system.out.println(wrong); } break; case 4: system.out.println("which lowest numbered element in periodic table?"); ans = sc.nextline(); if (ans.equals("hydrogen") || ans.equals("hydrogen")) { system.out.println(correct); } else { system.out.println(wrong); } break; case 5: system.out.println("which unit measures coulombs per second?"); ans = sc.nextline(); if (ans.equals("ampere") || ans.equals("ampere")) { system.out.println(correct); } else { system.out.println(wrong); } break; default: system.out.println("stick rules! 1-5!"); } } else { system.out.println("not liking attitude, want hear big yes!"); } } } as mentioned, i'm pretty new in java, you'll find more errors sure, , "style" may terrible, suggestions welcome! :)
you have forgotten add () brackets in line
ret = sc.nextline;
also nextline not nextline
change ret = sc.nextline;
ret = sc.nextline();
Comments
Post a Comment