When i enter a fahrenheit Value like 55 F it works pefectly fine, but if i type a Celcius value it gives me a massive error liek 5 C doesnt work. what am i missing, or what have i done wrong
import java.util.*;
public class tempConversion { // The start of the main class
public static void main ( String[] args ) {
System.out.println ( "Enter a Value and Temperature (e.g. 67 F): " );
double val = 0;
double c = 0.0;
double f = 0.0;
String temp = " ";
Scanner scan = new Scanner( System.in );
val = scan.nextDouble();
temp = scan.next();
if (temp.equals( " F " ) )
{
f = val;
c = ( 5.0 / 9.0 ) * ( f - 32 );
System.out.printf ( "%.2f Fahrenheit, = %.2f Celsius.\n", val, c );
}
else
{
c = val;
f = ( 1.8 * c * 32 );
System.out.printf ( "%.2f Celcius, = %.2f Fahrenheit,\n", val, f );
}
}
}
Aucun commentaire:
Enregistrer un commentaire