-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZadacha1.java
More file actions
29 lines (27 loc) · 855 Bytes
/
Zadacha1.java
File metadata and controls
29 lines (27 loc) · 855 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
27
28
29
package MainPackage;
import java.util.Scanner;
public class Zadacha1 {
public static double celsiusToFahrenheit(double c){
return 9.0/5.0*c+32;
}
public static double fahrenheitToCelsius(double f){
return 5.0/9.0*(f-32);
}
public static void convert(){
System.out.println("(0)Celsius to fahrenheit (1)Fahrenheit to celsius");
Scanner S=new Scanner(System.in);
System.out.print("Choice: ");
int choice;
choice=S.nextInt();
while(choice<0||choice>1) {
System.out.print("Choice: ");
choice=S.nextInt();
}
System.out.print("T=");
double t;
t=S.nextDouble();
if(choice==0) System.out.println(celsiusToFahrenheit(t));
if(choice==1) System.out.println(fahrenheitToCelsius(t));
S.close();
}
}