hey so I'm relatively new to java (2 weeks or so) and I have latched onto the idea of if and else if statements. I made this program to output the details of an animal, which include name, height, how many legs it has and whether or not it has a tail. For the last statement, I tried using an if statement to make it choose which line to output, based on whether hasTail is true, or false. However this doesn't work for some reason, and just outputs that a human has a tail, no matter what. Please help!
here is my code so 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"); } }
and when I run this file (shift - f6 in netbeans IDE) this is what the output is:
The animal is a Human
A Human has 2 legs
A Human is 1.8 meters tall
A Human has a tail
if you can help thanks so much!
skeptile