-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCelsiusToFahrenheitTable.java
More file actions
36 lines (29 loc) · 1.1 KB
/
Copy pathCelsiusToFahrenheitTable.java
File metadata and controls
36 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.text.*;
/**@author Lemuel M. Uhuru
* @Date July 13, 2013
* Book Title: From Control Structures through Objects by Tony Gaddis
* Page: 268 Challenge 11: Celsius to Fahrenheit Table
*
* @Description Write a program that displays a table of the Celsius temperatures
* 0 through 20 and their Fahrenheit equivalents. Your program should use a loop
* to display the table.
*/
public class CelsiusToFahrenheitTable {
public static void main(String[] args) {
// Table Header
System.out.println(" Temperature (Degrees)");
System.out.println("----------------------------------------------");
System.out.println(" Celsius " + " Fahrenheit");
// Decimal formatting
NumberFormat df = DecimalFormat.getInstance();
df.setMaximumFractionDigits(2);
// Counter variable
int count = 20;
double fahrenheit;
// For loop to calculate fahrenheit and display table data
for(int i = 0; i<=count; i++){
fahrenheit = 9/5.0*i+32;
System.out.println(" " + i + " " + df.format(fahrenheit));
}
}
}