WAP in Java to input temperature in Fahrenheit and convert it in Celsius. C= (F-32)*5/9
Question
WAP in Java to input temperature in Fahrenheit and convert it in Celsius. C= (F-32)*5/9
Solution
Sure, here is a simple Java program that takes temperature in Fahrenheit as input and converts it to Celsius:
import java.util.Scanner;
public class TemperatureConversion {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter temperature in Fahrenheit: ");
double fahrenheit = input.nextDouble();
double celsius = (fahrenheit - 32) * 5 / 9;
System.out.println("Temperature in Celsius: " + celsius);
}
}
Here's how it works:
-
We import the Scanner class from the java.util package. This class is used to get user input.
-
We declare a class named
TemperatureConversion. -
Inside the
TemperatureConversionclass, we declare themainmethod. This is the entry point for any Java program. -
Inside the
mainmethod, we create an instance of the Scanner class namedinput. -
We prompt the user to enter a temperature in Fahrenheit.
-
We use the
nextDoublemethod of theinputobject to get the user's input as a double. We store this value in thefahrenheitvariable. -
We convert the temperature to Celsius
Similar Questions
Create a Temprature class. Make two methods :1. convertFahrenheit - It will take celsius and will print it into Fahrenheit.2. convertCelsius - It will take Fahrenheit and will convert it into Celsius.
Write code that allow the user to enter the temperature in degrees Celsius. The program should convert it and print it in Fahrenheit degrees using the following formula: Fahrenheit = (Celsius * 9/5) + 32 For example, if the user enters 0, then the program will print "Temperature in Fahrenheit: 32.0"
Given the temperature of the day as Celsius as input. Do convert Celsius into Fahrenheit using the formulae: Fahrenheit = ((celcius*9) /5)+32Input Format:Accept a floating point(double) value for Celsius.Output Format:Print the Fahrenheit value with respect to two decimal places(Example: 23.52F)Constraints:1<=N<=10^15Sample Input 1:32.4Sample Output 1:90.32FSample Input 2:20.0
Develop a Java program that creates a simple GUI application for atemperature converter. The program should allow users to converttemperatures between Celsius and Fahrenheit.
Convert 49 degrees F to degrees Celsius. If necessary, round your answer to the nearest tenth of a degree. Here are the formulas. C=5/9 (F-32 F=9/5 C+32
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.