Jump to content

Help me with my homework / mini program

KungPaoChino

Can anyone find the error?? When I compiled something was wrong with the string.

 

This is in java. Program used JGrasp. Program is currently in WIP

 

 

public class AllenDengHw1D
{
   public static void main(String[] args)
   {
      //Sides and additions of sides
     
      double sideOne = 3.3 ;
      double sideTwo = 4.4 ;
      double sideThree = 5.5 ;
     
      double sideOneAndTwo = sideOne + sideTwo ;
      double sideOneAndThree = sideOne + sideThree ;
      double sideTwoAndThree = sideTwo + sideThree ;
     
     
      if (sideOneAndTwo > sideThree && sideOneAndThree > sideTwo && sideTwoAndThree > sideOne);
         System.out.println("The sides length " + sideOne  " ," + sideTwo  " ,and "  + sideThree " make a triangle.");
   }
}   

 

The homework problem .  The triangle inequality theorem in mathematics states that the sum of any two sides of a triangle MUST be greater than the third side. The program will create three decimal variables representing three sides of a potential triangle. It must then check all possible combination to make sure that it passes the triangle equality. 

LTT CSGO SERVER! IP 8.12.22.45!~  Connect by connecting on csgo console

Use console command "connect"   --->  connect 8.12.22.45

Link to comment
Share on other sites

Link to post
Share on other sites

System.out.println("The sides length " + sideOne +  " ," + sideTwo +  " ,and "  + sideThree + " make a triangle.");

Missing three '+'. 

 

EDIT: Lightz beat me to it.

TrinityFX


CPU: i5-4440 @ 3.1Ghz RAM: Crucial 1 x 4GB @ 1.6Ghz  MOTHERBOARD: MSI Z87-G41 PC Mate GPU: PCS+ HD 7870 Ghz Edition | CASE: NZXT Source 210 Window | HDD #1: Toshiba 3.5" 500GB HDD #2: Toshiba 2.5" 500GB PSU: Cougar SL500 OS: Windows 8.1 Pro 


 | https://pcpartpicker.com/b/2wccCJ |

Link to comment
Share on other sites

Link to post
Share on other sites

System.out.println("The sides length " + sideOne  +" ," + sideTwo  +" ,and "  + sideThree +" make a triangle.");

Interesting. Before I made the thread, I tried compiling the program with that in the string, yet it failed on me. O_O

LTT CSGO SERVER! IP 8.12.22.45!~  Connect by connecting on csgo console

Use console command "connect"   --->  connect 8.12.22.45

Link to comment
Share on other sites

Link to post
Share on other sites

That is the longest if statement I've seen so far :P

More like, those are the longest names I've seen on variables so far xD

Link to comment
Share on other sites

Link to post
Share on other sites

More like, those are the longest names I've seen on variables so far xD

There's nothing wrong with using long name variables. It can make your code a lot more readable.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×