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

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

/*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));
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.