Print a table of Celsius temperatures from -10 to 40 in steps of 10 with their Fahrenheit and Kelvin values, aligned in columns.
Solution
Main.java
public class Main {
public static void main(String[] args) {
System.out.printf("%8s%12s%10s%n", "Celsius", "Fahrenheit", "Kelvin");
for (int c = -10; c <= 40; c += 10) {
double f = c * 9.0 / 5 + 32; // 9.0 avoids integer division
double k = c + 273.15;
System.out.printf("%8d%12.1f%10.2f%n", c, f, k);
}
}
}
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!