We appreciate your visit to Write a program that allows the user to convert a temperature given in degrees from either Celsius to Fahrenheit or Fahrenheit to Celsius Use the. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!
Answer :
Answer:
import java.util.Scanner;
public class num6 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the temperature");
double temp = in.nextDouble();
System.out.println("Enter C to convert to celsius or F for fahrenheit");
String con = in.next();
if (con.equalsIgnoreCase("C")) {
double Degrees_C = 5 * (temp - 32) / 9;
System.out.println("The temperature of " + temp + "F in Celcius is" +
" " + Degrees_C);
} else if (con.equalsIgnoreCase("F")) {
//Degrees_F = (9(Degrees_C)/5) + 32)
double Degrees_F = (9 * (temp) / 5) + 32;
System.out.println("The temperature of " + temp + " celcius in Farenheit is" +
" " + Degrees_F);
} else {
System.out.println("Invalid value for conversion");
}
}
}
Explanation:
Use Scanner Class to prompt and receive user input
Use string method equalsIgnoreCase in an if statement to test the conversion to degrees celcius or farenheit
evaluate and output the values based on the equation given in the question
Thanks for taking the time to read Write a program that allows the user to convert a temperature given in degrees from either Celsius to Fahrenheit or Fahrenheit to Celsius Use the. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!
- Why do Businesses Exist Why does Starbucks Exist What Service does Starbucks Provide Really what is their product.
- The pattern of numbers below is an arithmetic sequence tex 14 24 34 44 54 ldots tex Which statement describes the recursive function used to..
- Morgan felt the need to streamline Edison Electric What changes did Morgan make.
Rewritten by : Barada
The program is a temperature converter which converts temperature values based on the unit and value inputted by the user. The program is written in python 3 thus ;
unit = input('your temperature unit : ')
#takes unit input in Celcius (C) or Fahrenheit (F)
unit = unit.lower()
#changes the input to lower case
value = eval(input('temperature value : '))
#takes temperature value input
def converter(value):
#initialize a function named converter which takes in the inputted value as parameter
if(unit == 'c'):
#Checkthe unit entered by user.
deg_c = 5*(value - 32)/9
return deg_c
else:
deg_f = (9*(value)/5)+ 32
return deg_f
#returns the converted temperature values.
print(converter(value))
A sample run of the program is attached.
Learn more : https://brainly.com/question/19539086