what is wrong with my code???
Most of my variable say that they cannot be resolved and I think my bracket/culrys are in the wrong place.
Code java:
import java.util.*;
public class test2 {
public static void main(String[] args) {
Scanner k=new Scanner(System.in);
System.out.println("What is your first name?");
String f =k.nextLine();
System.out.println("What is your last name?");
String l=k.nextLine();
String n= (f + " " + l);
System.out.println("Hello, " + n);
System.out.println("How was your day? (good/bad)");
String d=k.nextLine();
if (d.equals("good")) {
System.out.println("That's great. I'm so happy for you, " + f);
System.out.println("What made your day so great");
String w=k.nextLine();
System.out.println("That is awesome!");
}
else if (d.equals("bad")) {
System.out.println("That's terrible! I feel so bad for you, " + f);
System.out.println("What made your day bad");
String w=k.nextLine();
System.out.println("That stinks!");
}
System.out.print("Did you have a good Thanksgiving?");
String t=k.nextLine();
if (t.equals("yes"))
{
System.out.println("Cool");
System.out.println("Was your whole family there?");
String y=k.nextLine();
}
if (y.equals("yes"))
{
System.out.print("That must have been fun");
System.out.println("Was your whole family there?");
String y=k.nextLine();
else if (y.equals("no"))
{
System.out.print("That's too bad");
System.out.println("Did you have at least most of your family there?");
String h=k.nextLine();
}
if (h.equals("yes"))
{
System.out.print("That's good");
else if (h.equals("no"))
{
System.out.print("Thats too bad, but at least you had a good Thanksgiving");
}
else if (t.equals("no"))
{
System.out.println("Why not");
System.out.println("That's too bad");
System.out.println("Was your whole family there?");
String y=k.nextLine();
}
else if (y.equals("no"))
{
System.out.print("That's too bad");
System.out.println("Did you have at least most of your family there?");
String h=k.nextLine();
}
}
if (h.equals("yes"))
{
System.out.print("That's good");
if (h.equals("no"))
{
System.out.print("Your Thanksgiving must have been terrible");
}
}
}
Re: what is wrong with my code???
Please explain what the problem is. Post the program's output and add some comments showing what you want the output to look like.
Please Edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
Re: what is wrong with my code???
I have had a go at tidying it all up. Some of your if and if else statements were muddled and some curly brackets needed altering.
I have never seen so many if and else statements to be honest but let me know how this works for you:
Let me know how it goes and if there is anything missing.
Also Tip: Try using 'Format' to arrange the code nicely. When i first started it was near impossible to work with, i had to delete all the spaces to see where i was going with it.
--- Update ---
P.S.
Why is my Java code not Color coded in my post above like the OP is ?
Re: what is wrong with my code???
@djl1990
Why are you doing the OPs work for him? Spoonfeeding code doesn't help an OP learn how to debug and fix his code.
Where is your explanation of the problems with the OPs code and what you did to fix it?
Re: what is wrong with my code???
I did say some If and Else's were muddled as were some curly brackets.
I also advised to Format his code and delete unnecessary large spaces which will make it easier for future problems.
There were no major issues as such, more layout issues.
I don't see what else i can explain ?
I should also note I am also a complete beginner so any explanations i try to attempt would only confuse the OP.
Re: what is wrong with my code???
So why spoonfeed working code the OP can copy without having to learn how to find problems in his code and how to fix it?
Re: what is wrong with my code???