Respuesta :
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
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
