Skip to content

Commit baf6319

Browse files
authored
Merge pull request #4 from kylewehrung/java-practice
Convert celsius to fahrenheit, fun!
2 parents 91b72ad + 6a44034 commit baf6319

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ch03/CelsiusToFahrenheit.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.Scanner;
2+
3+
public class CelsiusToFahrenheit {
4+
5+
public static void main(String[] args) {
6+
// Create variables
7+
double celsius;
8+
double fahrenheit;
9+
final int FREEZING_TEMP = 32;
10+
Scanner input = new Scanner(System.in);
11+
12+
// Ask for number in celsius, then save that input as the celsius variable
13+
System.out.print("Enter a temperature in Celsius: ");
14+
celsius = input.nextDouble();
15+
System.out.printf("%.1f celsius\n", celsius);
16+
17+
// Conver celsius to fahrenheit
18+
fahrenheit = (celsius * 9.0/5.0) + (FREEZING_TEMP);
19+
20+
// Display result!
21+
System.out.printf("%.1f celsius = %.1f fahrenheit\n", celsius, fahrenheit);
22+
23+
24+
25+
}
26+
27+
28+
}

0 commit comments

Comments
 (0)