Programming Fundamentals/Functions/Java: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Creating |
(No difference)
|
Revision as of 01:52, 20 January 2017
variables.java
import java.util.*;
class Main {
private static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
double f;
double c;
f = getF();
c = calculateC(f);
displayResult(f, c);
}
private static double getF() {
double f;
System.out.println("Enter Fahrenheit temperature:");
f = input.nextDouble();
return f;
}
private static double calculateC(double f) {
double c;
c = (f - 32) * 5 / 9;
return c;
}
private static void displayResult(double f, double c) {
System.out.println(f + "° Fahrenheit is " + c + "° Celsius");
}
}
Try It
Copy and paste the code above into one of the following free online development environments or use your own Java compiler / interpreter / IDE.