In my program, a user inputs a float
number with TEMP (for example TEMP 10.05
).
The program should take only the float
part and convert it into fareheit. And finally printing out the result in float.
How could I do that?
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("The following program takes a float value with the word 'TEMP'in celcius, and converts into farenheit");
System.out.println("Enter the temperature with TEMP: ");
while (true) {
String input = s.next();
//converting into farenheit
if (input != null && input.startsWith("TEMP")) {
float celsius = Float.parseFloat(input.substring(input.indexOf(' ') + 1));
float tempFaren=celcius+32.8;
// float=result
System.out.println("Temperature in farehheit is : "+tempFaren+ " F.");
}
}
}
The program shows this error: