Jump to content

Java Help Requested

Go to solution Solved by Smokeythebear,

System.out.println(inches + "inches are equivalent to " + var);

 

If I'm remembering this correctly.

Hey guys,

 

Im taking an intro class in programming in Java for a possbile future job opertunity.  Currently the project calls for this statment to be printed " 10.0 inches are equivalent to 25.4 centimeters. ". I'm having inssues formating the print line correctly.  Heres my code for more detail. 

 

 

---------------------------------------------------------------------------------------------------------------------------------------------------

 

public class MetricLength
// Lab1
{
public static void main( String [] args )
   {
                        double var;
   double CM_PER_INCH;
   
      CM_PER_INCH = 2.54;
   
   double NM_OF_INCH;
      
      NM_OF_INCH = 10;
      
      var = NM_OF_INCH * CM_PER_INCH;
       
   
     System.out.println( );
                              
      
      
      
      
      }
      
}

---------------------------------------------------------------------------------------------------------------------------------------------------

 

Thanks in advance!

"45 ACP because shooting twice is silly!"

Link to comment
https://linustechtips.com/topic/655295-java-help-requested/
Share on other sites

Link to post
Share on other sites


System.out.println(NM_OF_INCH * CM_PER_INCH);

or 

System.out.println(var);

 

 

Oh, and I would just format things a bit differently. It will make your life easier in the long run. 

 


public class MetricLength(){

    public static void main(String[] args){

         double cmPerInch = 2.5; 

         double inches = 10; 

         double centimeters = cmPerInch * inches; 

         System.out.println(centimeters); 

    }

}

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
https://linustechtips.com/topic/655295-java-help-requested/#findComment-8422805
Share on other sites

Link to post
Share on other sites

3 minutes ago, MaxBunny said:

Java is pretty horrible. You're going to hate your life if you pursue this path. :P

I should probably rephrase that, currently I need to get into coding and practice.  So far this is decent practice and I'm catching on fairly quick.  However Powershell is needed for my ACTUAL job opportunity. 

 

5 minutes ago, djdwosk97 said:

System.out.println(NM_OF_INCH * CM_PER_INCH);

or 

 


System.out.println(var);

 

Hmmm, I'll try that.  Thank you!

"45 ACP because shooting twice is silly!"

Link to comment
https://linustechtips.com/topic/655295-java-help-requested/#findComment-8423223
Share on other sites

Link to post
Share on other sites

13 minutes ago, djdwosk97 said:

-snip-

Note taken on the formatting, thank you!  Also I need the output to be " 10.0 inches are equivalent to 25.4 centimeters. "

 

Currently the error I'm getting with my code is as follows:

 

--------------------------------------------

MetricLength.java:21: error: ')' expected
     System.out.println( "10.0 inches are equivalent to"(var) );
                                                        ^
MetricLength.java:21: error: not a statement
     System.out.println( "10.0 inches are equivalent to"(var) );
                                                         ^
MetricLength.java:21: error: ';' expected
     System.out.println( "10.0 inches are equivalent to"(var) );
                                                            ^
3 errors
 

 

--------------------------------------------

 

 

"45 ACP because shooting twice is silly!"

Link to comment
https://linustechtips.com/topic/655295-java-help-requested/#findComment-8423779
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

×