Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: if-else statement not working and dont know why

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default if-else statement not working and dont know why

    My if else statement is not working...it keeps telling me that the else in the statement is a syntax error and that I should remove it. Whats wrong with it?
     
    package Homework2;
    import java.util.Scanner;
    public class Homework2 {
     
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    		System.out.println("Welcome to the Triangle Program.");
     
    		Scanner keyboard = new Scanner(System.in);
     
    		System.out.println("Please enter the length of side 1:");
    		double a = keyboard.nextDouble();
     
    		System.out.println("Please enter the length of side 2:");
    		double b = keyboard.nextDouble();
     
    		System.out.println("Please enter the length of side 3:");
    		double c = keyboard.nextDouble();
     
    		if(a*a + b*b == c*c);
    		{
    			System.out.println("This is a Right Triangle");
    		}
    		else 
    		{
    			System.out.println("This is NOT a right triangle");
    		}
    	}
     
    }


  2. #2
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: if-else statement not working and dont know why

    You have a semicolon after the if statement. You need to remove it.

  3. The Following User Says Thank You to camel-man For This Useful Post:

    GregBrannon (September 14th, 2014)

Similar Threads

  1. [SOLVED] If Statement not working
    By Szpak in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 5th, 2014, 05:37 PM
  2. If else statement not working.
    By DarkestLord in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 13th, 2014, 01:17 PM
  3. if else if elese if.... statement not working
    By ahans in forum Loops & Control Statements
    Replies: 4
    Last Post: October 25th, 2013, 01:54 PM
  4. Replies: 2
    Last Post: June 25th, 2013, 06:33 AM
  5. code is right but i dont understant how its working
    By hwoarang69 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 31st, 2012, 12:22 AM