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"); } }
Comments
Leave a comment