0
import javax.swing.JOptionPane;
public class test{
	public static void main(String args[]){
		
		String numT = JOptionPane.showInputDialog(null,"Please enter a value.");
		double num1 = Double.parseDouble(numT);
		
		System.out.println("Fahrenheite = "+num1+"\nCelcius = "+convertFtoC( num1 ));
	}
	
	public static double convertFtoC ( double num1 ){
			
		return ((5/9)*(num1-32));
	}
}

why the value return is zero? hrm... can anyone point out my mistake? thanks

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by fardoonmuhafiz
0

the mistake is that you think your calculation results in a floating point number. It doesn't, it results in an integer number.

0
/*this code shld work...5/9 returns 0 so use 5/9.0 which returns float value*/
import javax.swing.JOptionPane;
public class Test{
public static void main(String args[]){


String numT = JOptionPane.showInputDialog(null,"Please enter a value.");
double num1 = Double.parseDouble(numT);


System.out.println("Fahrenheite = "+num1+"\nCelcius = "+convertFtoC( num1 ));
}


public static double convertFtoC ( double num1 ){


return ((5/9.0)*(num1-32));
}
}

Edited by happygeek: fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.