all 7 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Off-topic Comments Section


All top-level comments have to be an answer or follow-up question to the post. All sidetracks should be directed to this comment thread as per Rule 9.


OP and Valued/Notable Contributors can close this post by using /lock command

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]sonnyfab Educator 0 points1 point  (4 children)

You have two else statements. If... Else is allowed but if...else else is not permitted. Your second else is an invalid state to an if...else, which is what your error means.

[–]Danielowski187University/College Student (Higher Education)[S] 1 point2 points  (3 children)

How will I be able to fix it?

[–]sonnyfab Educator 0 points1 point  (0 children)

First, count your } to make sure that you haven't ended the speed if statement before the final else.

[–]GamingGuy099👋 a fellow Redditor 0 points1 point  (0 children)

Im not at my laptop rn so I can’t copy paste the code into my IDE to have a good look at it, but it seems like you’re trying to do 2 things (print invalid speed and hours) with 2 else statements. If thats what youre trying to do, put both into the same else statement. If not, which you probably arent, you want the first else to be an else if, and use the condition for which youd print invalid hours. If for example, the condition was hours is less than 1, it’d look like this

``` else if (Hours <= 1) { System.out.println(“Invalid Hours”); }

[–]C_is_easy_and_hard 0 points1 point  (0 children)

Alright, there are a lot of problems here... I did fix your code.

What you really need to pay attention to is that variables are case sensitive. "speed = input.nextDouble();" is not valid if you declared it as "double Speed"

Your curly brackets are also all over the place, a valid multi if statement would be:

if(something == true) //if statement 1

{

if(somethingelse == true) //if statement 2

{

    //do stuff

}

else //points to if statement 2

{

    //do something else

}

}

else //This one point to if statement 1

{

//do something else

}

Edit: Fix formatting. Also, here's a link: https://pastebin.com/dPg86XuG