+ 1
Converting Program
I have this Program due and I honestly cant get past the first part. I cant figure out how to do this and it is due tonight. help pleaseee!
6 Antworten
0
// Float C = F * (9 / 5) -32;
float C = (F-32) * (5f / 9f); // correct
with 5/9 you need decimal result but 5/9 are integers without decimal parts
use 5f/9f for float decimal result instead
EDIT: float C = (F-32) * 5 / 9;
without () around 5/9 is also ok because (F-32) is float result and it converts next operations with integers to floats
use sololearn playground and share link, so we can see your progress
+ 1
hey Jessica why not share the code and state the part that seem to trouble you
0
Where is Program?
Share your tried code link, so one can identify and try to solve..
0
This is the assignment:
Create a file ImperialToMetricUnitsConvertor.java. Write a program that converts, and prints the provided values and the converted values with the appropriate unit symbols for the following:
•Temperature - tempInF = 25.50
◦Convert from Fahrenheit to Celsius
◦Convert from Fahrenheit to Kelvin
•Mass - massInPounds = 121
◦Convert from Pounds to Kilograms
◦Convert from Pounds to Grams
•Distance - distanceInMiles = 35.75 | distanceInFeet = 6.7
◦Convert from Miles to Kilometers
◦Convert from Feet to Meters
•Volume - volumeInGallons = 220.13 | volumeInPints = 44.89
◦Convert from Gallons to Liters
◦Convert from Pints to Milliliter
All values must be printed with the appropriate unit symbols. For example, lb is the unit symbol for weight in pounds.
This is the first part of the assignment and I keep getting errors:
import java.util.Scanner;
public class FahrenheitToCelsius {
public static void main(String[] args) {
float temperature;
Scanner in = new Scanner(System.in);
/*User Inputs temperature in Fahrenheit*/
System.out.print("Enter temperature in Fahrenheit:");
float F = in.nextFloat();
/*convert Fahrenheit to Celsius*/
Float C = F * (9 / 5) -32;
System.out.println(F + "F is equal to" + C +" F");
}
}
0
F to °C ,Deduct 32, then multiply by 5, then divide by 9
So C=(f-32)*5/9
°F to kelvin°F, K=>(F-32)*5/9 +273 = (C+273) ;
That part has no errors but may be output wrong, so check again....
Edit:
Jessica
import java.util.Scanner;
public class FahrenheitToCelsius {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
/*User Inputs temperature in Fahrenheit*/
System.out.print("Enter temperature in Fahrenheit:");
float F = in.nextFloat();
/*convert Fahrenheit to Celsius*/
float C =(F-32)*5/9;
System.out.println(F + "°F is equal to" + C +"°C");
System.out.println (F + "°F is equal to " +(C+273)+"K");
}
}
0
Plece watching a error line with row
And column number