3.
The following is the formula to convert a Celsius degree to Fahrenheit degree:
Fahrenheit = (9/5) Celsius + 32
Write a program to prompt user to enter a Celsius degree, convert it to Fahrenheit and display
(1 pound = 16 ounces)
This is meant to be written in Java 14.0
import java.util.*;
public class Convert
{
Scanner s= new Scanner(System.in);
//function to conver celcius to farenheit
void faren()
{
float f,c;
//taking user input
System.out.println("Enter the temperature in Celsius");
c=s.nextFloat();
//converting to farenheit
// (9/5)=1.8
f=(1.8f*c)+32;
//displaying result
System.out.println("The temperature in farenheit is: "+f);
}
//function to conver onces in pounds and ounces
void pound()
{
int o,p,e;
//taking user input
System.out.println("\n\nEnter the weight in ounces");
o=s.nextInt();
//converting to pounds and ounces
p=o/16;
e=o%16;
//displaying result
System.out.println(o+" ounces = "+p+" pounds and "+e+" ounces");
}
public static void main(String[] args)
{
Convert x=new Convert();
x.faren();
x.pound();
}
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.