Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
okay well i figured out this much with some help from my friend. My issue is to make it so that the answer will give me a few decimal places. ie if the answer is 89.6 my current program is giving me 89.
import java.util.*;
public class WWWTempConvert
{
public static void main(String[] args)
{
System.out.println("I will convert from either degrees Celsius to Fahrenheit or from degrees Fahrenheit to Celsius.");
System.out.println("Please enter a number with either C or c for Celsius or F or f for Fahrenheit:");
System.out.println("If you wish to quit please press Q or q");
Scanner keyboard = new Scanner(System.in);
int num;
String unit;
String prompt;
while (keyboard.hasNext()) {
prompt = keyboard.next();
if (prompt.equalsIgnoreCase("Q")) {
System.out.println("Exiting");
System.exit(0);
}
unit = keyboard.next();
num = Integer.parseInt(prompt);
if (unit.equalsIgnoreCase("C")) {
System.out.println("The value in Fahrenheit is:");
System.out.println(((9*num)/5 + 32)+" F");
}
else if (unit.equalsIgnoreCase("F")) {
System.out.println("The value in Celsius is:");
System.out.println(((5*(num-32)/9))+" C");
} else
System.out.println("Error.");
System.out.println("Enter next value or enter q or Q to quit: ");
}
}
}

Hi
I'm not familiar with Java, but if it can handle decimals try changing one of the numbers to decimal, maybe it treats your sum as integer because your numbers are integers.
Try changing one of them or all to decimal.System.out.println(((9.0*num)/5.0 + 32.0)+" F");

![]() |
bat file
|
Using a Macro to copy and...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |