Write java programs with the output to the following questions:. 1. write a program that converts a temperature from celcius to Fahrenheit. It should (1) Prompt the user for input (2) read a double value from the keyboard (3) calculate the result. For example: it should display "24.0 C = 75.2 F".
Answers
Answered by
2
Question:-
- Write java programs with the output to the following questions:.
- write a program that converts a temperature from celcius to Fahrenheit. It should (1) Prompt the user for input
- read a double value from the keyboard
- calculate the result.
- For example: it should display "24.0 C = 75.2 F".
Code:-
package Coder;
import java.util.*;
public class Temp {
/*
*Code Written By :-
*@swetank232894
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Temperature in Celcius?");
double c=sc.nextDouble();
double f=((9*c)/5)+32;
System.out.println("Converting to Fahrenheit...");
System.out.println(c+"°C="+f+"°F");
}
}
Variable Description:-
- c:- To accept temperature as input
- f:- To calculate and store temperature in Fahrenheit
•Output Attached
Attachments:
Answered by
2
import java.util.Scanner;
public class CelsiusToFahrenheit {
public static void main(String[ ] args) {
System.out.print("Celsius - ");
double celsius = new Scanner(System.in).nextDouble( );
System.out.printf("%.3f °C = %.3f °F", celsius, ((celsius * 9) / 5) + 32);
}
}
Sample I/O:
Celsius - 24
24.000 °C = 75.200 °F
Similar questions