Answer to Question #25650 in Java | JSP | JSF for Will

Question #25650
OK so I'm relatively new to java, and I am trying to create a simple program in which it stores data about an animal, and then displays that data in viewable format. This is what I have to far.

public class HomeProject1a{
public static void main (String [] args){
String name = "Human";
int numLegs = 2;
double height = 1.8;
boolean hasTail = false;

System.out.println("The animal is a " + name);
System.out.println("A " + name + " has " + numLegs + " legs");
System.out.println("A " + name + " is " + height + " meters tall");
if (hasTail = true) System.out.println("A " + name + " has a tail");
else if (hasTail = false) System.out.println("A " + name + " doesn't have a tail");

the problem is the if and else if statements. I do not know how to make java recognise them as if statements, and if I run the program, this is the output:

The animal is a Human
A Human has 2 legs
A Human is 1.8 meters tall
A Human has a tail

any help?
1
Expert's answer
2013-03-06T06:05:38-0500
public class HomeProject1a{
public static void main (String [] args){
String name = "Human";
int numLegs = 2;
double height = 1.8;
boolean hasTail = false;

System.out.println("The animal is a
" + name);
System.out.println("A " + name
+ " has " + numLegs + " legs");
System.out.println("A " + name
+ " is " + height + " meters tall");
if (hasTail)

System.out.println("A " + name + " has a tail");
else
System.out.println("A
" + name + " doesn't have a tail");
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS