forked from Programming-Club-IAU/Task-1.3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask3.java
More file actions
56 lines (39 loc) · 1.3 KB
/
Task3.java
File metadata and controls
56 lines (39 loc) · 1.3 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Scanner;
import java.util.InputMismatchException;
public class Task3{
public static void main(String[] args){
Scanner scan= new Scanner(System.in);
char Convert;
double Num;
double temperature;
System.out.println("Welcome to the temperature converter");
while (true){
try{
temperature = 0;
System.out.println("Enter your Value or 0 for exit :");
Num = scan.nextDouble();
if (Num == 0 ){
break;
}
System.out.println("Convertion From Fahrenheit to Celsius (C) or Celsius to Fahrenheit (F) ? ");
Convert = scan.next().charAt(0);
if (Convert == 'C' || Convert == 'c') {
temperature = (Num - 32) * 5/9 ;
System.out.println(temperature+"C");
}
else if (Convert== 'F' || Convert=='f'){
temperature= (Num * 9/5)+32;
System.out.println(temperature+"F");
}
else {
System.out.println("Enter valid input please ! ");
}
}
catch(InputMismatchException e ){
System.out.println("Wrong input");
scan.nextLine();
}
}
System.out.println("Goodbye!");
}
}