Link to home
Start Free TrialLog in
Avatar of jerry-2112
jerry-2112Flag for Afghanistan

asked on

New to Java Using Eclipse for a class with only C# programming in the past

I'm in a Java programming class.  Pretty basic for most of you guys.  I've only done C# programming in the past.  Pretty new to programming to start with anyway.  Already getting errors on the following program.  Trying to us the \n to start the next line.  Something I never did in C#.  Here is a look at my code and the errors I get.  Does anybody know a good began-er book with sample codes ? I work better by seeing examples.  Thanks please tell me what I'm missing here.

 String radius; //radius entered by user
        double radius1; // converted user input
             
        //get radius from user
        radius = JOptionPane.showInputDialog("Enter the Radius");
        //convert numbers from string to type Double
        radius1 = Double.parseDouble(radius);
     
        JOptionPane.showMessageDialog(null,  "The Diameter Is " +      (2*radius1)"\nThe Circumference Is "
       + (2 * Math.PI * radius1) " \nThe Area Is " + (Math.PI * radius1 * radius1));



When I separate I get it to work, but my lab is to have all in one display box.
This works but .....
 String radius; //radius entered by user
        double radius1; // converted user input
       
        //get radius from user
        radius = JOptionPane.showInputDialog("Enter the Radius");
        //convert numbers from string to type Double
        radius1 = Double.parseDouble(radius);
     
        JOptionPane.showMessageDialog(null,"The Diameter Is " + (2*radius1));
        JOptionPane.showMessageDialog(null,"\nThe Circumference Is "+ (2 * Math.PI * radius1));
        JOptionPane.showMessageDialog(null, " \nThe Area Is " + (Math.PI * radius1 * radius1));
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jerry-2112

ASKER

Thanks you are right about the (+) .  It did work.  1st I had to String result = .  Then in my display I had to display the result.
I would strongly recommend String.format for this case. Check the api docs