/    Sign up×
Community /Pin to ProfileBookmark

Intro to Java student

Hello I need to write a program that accepts yes or no or y and n. Ignoring cases.

I have got this far and. I don’t understand why my else if statement isn’t working

import java.util.Scanner;
public class Page191Q3 {

public static void main(String[] args) {
// TODO Auto-generated method stub

// Suppose you are writing a program that asks the user a yes or no question. Store answer in Stringvariableresponce.

boolean accept = false;
Scanner keyboard = new Scanner(System.in);
System.out.println(“Yes or No?”);

String response;
response = keyboard.nextLine();

if( response.equalsIgnoreCase(“yes”) || response.equalsIgnoreCase(“Y”) ); {
accept = true;
}
else if( response.equalsIgnoreCase(“no”) || response.equalsIgnoreCase(“n”) ); {
accept = false;

}else{
System.out.println(“You made a mistake”);


}
}

}

to post a comment
Java

3 Comments(s)

Copy linkTweet thisAlerts:
@NachfolgerSep 21.2020 — Look into proper if-statement Java syntax.

Invalid.
``Java<i>
</i>else if( response.equalsIgnoreCase("no") || response.equalsIgnoreCase("n") ); {<i>
</i>
`</CODE>

Invalid.
<CODE lang="Java">
`Java<i>
</i>else if( response.equalsIgnoreCase("no") || response.equalsIgnoreCase("n") ); {<i>
</i>
``


https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html
Copy linkTweet thisAlerts:
@emi2160475authorSep 22.2020 — @Nachfolger#1623506

yes it was invalid because of the semi-colons!
Copy linkTweet thisAlerts:
@NachfolgerSep 22.2020 — @emi2160475#1623507

Exactly. Good job finding the error, and best of luck with your semester projects.
×

Success!

Help @emi2160475 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...