Click here to Skip to main content
15,567,482 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Following is my code-

import java.util.Scanner;
public class Sample{

public static void main(String args[]){

Scanner myObj = new Scanner(System.in);
System.out.println(".........");
System.out.println("Welcome user.l hope you're well and safe from the pandemic. Do you want to test how beautiful you're?");
String answer = myObj.nextLine();
if (answer.equals("Yes") ){
System.out.println("Welcome");
} else if (answer.equals("No") ){
System.out.println("Ok");
}else{
System.out.println("Please enter yes or no");

System.out.println("Your name?");
String subAnswer = myObj.nextLine();
System.out.println("How old are you?");
int lastAnswer = myObj.nextInt ();
if (subAnswer.equals("Shruti")&&lastAnswer == 45){
System.out.println(subAnswer +"-you're 93% beautiful ");
}else if (subAnswer.equals("Alex")&&lastAnswer == 46){
System.out.println(subAnswer +"-you're 90% beautiful ");
}else if (subAnswer.equals("Alora")&&lastAnswer == 26){
System.out.println(subAnswer +"-you're 99% beautiful ");
}else{
System.out.println("You're not beautiful ");
}

}
}

What I have tried:

I want that when l enter yes in the first question,it continue and when l enter no it says so ok.
Posted
Updated 27-Jul-21 0:08am
Comments
Rudra Singh Jul2021 27-Jul-21 4:06am    
These are the errors-
compiler.java:32: error: reached end of file while parsing
}
^
1 error
Richard MacCutchan 27-Jul-21 4:42am    
Then obviously you have a closing brace missing.

Ranjeet, how many times must we tell you: Go to Java Tutorials Learning Paths[^] and learn the language.
 
Share this answer
 
Oh come on!
You've been here often enough, asked enough questions, had syntax errors explained toi you before.

What do you think
reached end of file while parsing
}
^
means?
It means it's expecting something - a close curly bracket - and it didn't get it.
And a trivial look at the code says where you forgot it.

Hint: What - exactly - are you expecting to do if the user starts by not entering "Y" or "N"? Did you want to ask for his name?
 
Share this answer
 
Comments
Rudra Singh Jul2021 27-Jul-21 5:20am    
Sir,l want that when user will enter yes in the first question then it will welcome and it will continue asking name and age.And when user'll enter no,it will say ok.and it will not ask name and age then.And as l have mentioned if user will say something else not yes or no then it will say please enter yes or no.Please provide this program or what problems are there in my program. It's my humble request sir.
OriginalGriff 27-Jul-21 5:58am    
"Please provide this program"
You know better than that.
You know we do not do you homework for you.

So what have you tried to do this? Apart form the code above which looks (if I'm honest) like it was thrown together without any thought or planning.
Rudra Singh Jul2021 27-Jul-21 7:12am    
Sir l don't mean that. I am just asking a help as a friend to you. Just tell me what are the problems in my program...
Rudra Singh Jul2021 27-Jul-21 7:13am    
,l want that when user will enter yes in the first question then it will welcome and it will continue asking name and age.And when user'll enter no,it will say ok.and it will not ask name and age then.And as l have mentioned if user will say something else not yes or no then it will say please enter yes or no.And also in my previous comment,l forgot to mention syntax. I was asking that can you help me in this program syntax.
Rudra Singh Jul2021 27-Jul-21 7:14am    
Sir l never give me works to you.l just keep my problems.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900