1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

java Mathematical decimal point error

Discussion in 'Java' started by an2new, Sep 5, 2011.

  1. an2new

    an2new New Member

    Joined:
    Sep 5, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Java math error.
    I got a prompt asking to covert from Fahrenheit to Celsius and it seem to compiled right and everything but the mathematical solution does not have the right decimal point. I tried everything I know please help. Example if you cal 72 F = 22.22 C...I got 72 F = 22.0 C. Here the program.
    Code:
    import java.util.Scanner;
    
    public class Handout1Project5
    {
        public static void main(String[] args)
        {
            Scanner scannerObject = new Scanner(System.in);
            
            System.out.println("Hello out there");
            System.out.println("I will converts degrees Fahrenheit to Celsius for you.");
            System.out.println("Enter a temperature in degrees Fahrenheit:  ");
            
            int user_Input;
            double degrees_Output;
            
            user_Input = scannerObject.nextInt();
            System.out.println("You entered:" + user_Input);
            degrees_Output = (((user_Input - 32) * 5) / 9);
            System.out.println(user_Input + " degrees Fahrenheit" + " = " + degrees_Output + " Celsius");
            System.out.printf("%d degrees Fahrenheit = %3.2f degrees Celsius %n", user_Input, degrees_Output);
            
        }
    }
     
    Last edited by a moderator: Sep 5, 2011
  2. an2new

    an2new New Member

    Joined:
    Sep 5, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    nvm thank you I have found out the solution. Please delete this thread.
     

Share This Page