Need help in java! "reached end of file while parsing"?
-
ok so i just started learning java tonight and was doing one of the projects in the book I'm learning from "programming video games for the evil genius" as i finished the project I kept trying to close the brackets but it kept saying "while expecting" and " reached end of file while parsing" I've re read the code and the book 6 times and i can't find the mistake. Any help would be really appreciated. Heres the code. The program is a maths flash card game. it randomly generates a simple sum and it gives you a set amount of time to figure out the answer //first, allow for input getting import javax.swing.*; //create a class named S1P4 public class S1P4 { private static int sign; //main method (throws Exception) added for Thread.sleep() public static void main (String[] args) throws Exception { //this will be how many 1/2 seconds the user gets int difficulty; difficulty = Integer.parseInt(JOptionPane.showInputDi… good are you?\n"+ "1 = Genius..\n"+"10 = Retart")); //this will tell the loop whether to continue or not: boolean cont = false; //the contents of the main method are about to be enclosed in a // do while loop... do { //reset cont to false cont = false; //random numbers for the equation double num1 = (int)(Math.round(Math.random()*10)); //this do..while loop prevents exceptions. num2 mustbe //declared outside of the do while so the "while" part can //see it. It will still be initialized inside the do part, //thought double num2; { //init num2 num2 = (int)(Math.round(Math.random()*3)); //will store answer double answer; //make stuff noticable System.out.println("\n\n*****"); if(sign==0) { //tell user and calculate answer System.out.println(num1+"times"+num2); answer = num1*num2; } else if(sign==1) { //tell user and calculate answer System.out.println(num1+"divided by"+num2); answer = num1/num2; } else if(sign==1) { //tell user answer and calculate System.out.println(num1+"plus"+num2); answer = num1+num2; } else if(sign==1) { //tell user answer and calculate System.out.println(num1+"minus"+num2); answer = num1-num2; } else { //tell user and calculate answer System.out.println(num1+"%"+num2); answer = num1%num2; } //make it easier to read... System.out.println("*****\n"); //count down from difficulty... use for a loop! for(int i = difficulty;i>=0;i--) { //count down at double speed! System.out.println(i+"..."); //instead of waiting a second. this time only //wait 1/2 a second per difficulty level Thread.sleep(500); } //print answer System.out.println("ANSWER:"+answer); //ask if they want to play again String again; again=JOptionPane.showInputDialog("Pla… again?"); //if user says yes set cont=true if(again.equals("yes")) cont = true; } while(cont); } }
-
Answer:
I'm not not sure what that code is supposed to do, but no matter, it appears your problem is at the end: if(again.equals("yes")) cont = true; } while(cont); } } you have no opening bracket for your if! Not sure what the double brackets after the while are supposed to accomplish though.
william belle at Yahoo! Answers Visit the source
Other answers
No... problem is here: //see it. It will still be initialized inside the do part, //thought double num2; { <----BAD...Take this out //init num2 num2 = (int)(Math.round(Math.random()*3));
Jeff
Related Q & A:
- I need help on what I need to buy or do.Best solution by Yahoo! Answers
- I need help with some horse questions, can you help me.Best solution by Yahoo! Answers
- I did something really bad and now i need help please help me.Best solution by Yahoo! Answers
- I need help with writing up the Java Code.Best solution by Yahoo! Answers
- What sort of opportunities are there to help people in Africa or places where people need help?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.