3 Replies - 1136 Views - Last Post: 03 October 2008 - 03:52 PM Rate Topic: -----

#1 willy8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 08

Hi need help w/ a temperature conversion program

Post icon  Posted 03 October 2008 - 03:31 PM

Hi What's up? I have this assignment for learning purposes only and I have no idea how to fix this error for temperature conversion. I only have 1 error, but I don't know where I went wrong.

import java.util.Scanner;

public class pp2_4
{
	public static void main (String[] args)
	{
		Scanner scan = new Scanner (System.in);

		final int BASE = 32;
		final double CONVERSION_FACTOR = 9.0 / 5.0;

		double fahrenheitTemp;
		int celsiusTemp;

		System.out.println ("enter a Fahrenheit temp ");
		fahrenheitTemp = scan.nextDouble();

		celsiusTemp = ( fahrenheitTemp - BASE ) / CONVERSION_FACTOR;

		System.out.println ("Celsius Temperature: " + celsiusTemp);
		System.out.println ("Fahrenheit Temperature: " + fahrenheitTemp);
	}



and this is my error...

pp2_4.java:18: possible loss of precision
found : double
required: int
celsiusTemp = ( fahrenheitTemp - BASE ) / CONVERSION_FACTOR;
^
1 error

Is This A Good Question/Topic? 0
  • +

Replies To: Hi need help w/ a temperature conversion program

#2 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2582
  • View blog
  • Posts: 15,605
  • Joined: 24-September 08

Re: Hi need help w/ a temperature conversion program

Posted 03 October 2008 - 03:46 PM

use all doubles.

celsiusTemp = ( fahrenheitTemp - BASE ) / CONVERSION_FACTOR;

is like

int = ( double - final int) / final double
Was This Post Helpful? 0
  • +
  • -

#3 willy8  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 08

Re: Hi need help w/ a temperature conversion program

Posted 03 October 2008 - 03:48 PM

View PostNeoTifa, on 3 Oct, 2008 - 03:46 PM, said:

use all doubles.

celsiusTemp = ( fahrenheitTemp - BASE ) / CONVERSION_FACTOR;

is like

int = ( double - final int) / final double


it worked thank you :-)
Was This Post Helpful? 0
  • +
  • -

#4 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2582
  • View blog
  • Posts: 15,605
  • Joined: 24-September 08

Re: Hi need help w/ a temperature conversion program

Posted 03 October 2008 - 03:52 PM

no prob. i made the same mistake with my first java project. ^_^ (that and i used Math.sqrt instead of Math.ppow cuz im backwards like that :P)

you should thank me so i look cool :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1