I need help making a program that outputs fer to cel from 32deg to 212deg, but I
ID: 3798324 • Letter: I
Question
I need help making a program that outputs fer to cel from 32deg to 212deg, but I need a chart displaying. (see below) I also need to use the scanner class as well.
Faren. Celcius
----------------------------
32.00 0.00
ect. ect.
212.00 100.00
2 El import java util. Scanner public class Temp public static void main (String args) Scanner input new Scanner System in) double celsius, fahrenheit; 10 System out print Enter a temperature in Fahrenheit fahrenheit input .next Double 12 celsius (fahrenheit 32) 5 9; 14 System out println. I fahrenheit I celsius "I") for 17 18 20 21 22 23 Output X Tempo (run x Temp (run) #2 x Enter a temperature in Fahrenheit: 32 I 32.0 0.0 I BUILD SUCCESSFUL (total time: 4 secondsExplanation / Answer
package temp;
import java.util.Scanner;
public class Temp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double celsius;
String fahrenheit = "";
System.out.print("Enter a temperature in Fahrenheit: ");
fahrenheit = input.next(); //store input as a string
System.out.println("Faren. Celcius");
System.out.println("---------------------------");
while(!fahrenheit.equals("q")){ //run a loop until user enter q for quitting the program
try{
Double.parseDouble(fahrenheit); //convert to double
celsius = (Double.parseDouble(fahrenheit) - 32) * 5 /9 ;
System.out.println( fahrenheit + " " + celsius );
}catch(NumberFormatException nfe){
System.out.println( fahrenheit + " " + fahrenheit );
}
fahrenheit = input.next(); // ask the user for new value to be converted.
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.