-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCelsiusFahrenheit.java
More file actions
26 lines (25 loc) · 959 Bytes
/
CelsiusFahrenheit.java
File metadata and controls
26 lines (25 loc) · 959 Bytes
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
import java.util.Scanner;
public class CelsiusFahrenheit {
public static void main(String args[]) {
double c, f; // temporature variables
int anw; // argument variable
Scanner temp = new Scanner(System.in);
anw = Integer.parseInt(args[0]);
if (anw == 0) {
System.out.println("Insert the Fahrenheit temperature to convert it to Celsius:");
f = temp.nextDouble(); // Fahrenheit input
c = (f-32)*(5/9); // transformation to Celsius
System.out.println(f + " Fahrenheit is " + c + " Celsius.");
}
else if (anw == 1) {
System.out.println("Insert the Celsius temperature to convert it to Fahrenheit:");
c = temp.nextDouble(); // celsius input
f = c * (9/5) + 32; // transformation to Fahrenheit
System.out.println(c + " Celsius is " + f + " Fahrenheit.");
}
else {
// wrong argument case
System.out.println("Wrong insert, please enter 0 or 1 to convert to Celsius or Fahrenheit, and try again!");
}
}
}