Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/App.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
import java.util.InputMismatchException;
import java.util.Scanner;

public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
Scanner input = new Scanner(System.in);
boolean flag = true;
while (flag) {
try{
System.out.println("------------------------------------\n" +
" Please select operation:\n" +
"\t1- C to F\n" +
"\t2- F to C\n" +
" SELECT ANY OTHER NUMBER TO QUIT\n");
double num;
switch (input.nextShort()) {
case 1:
num = takeNum();
displayNum(num, (num * 9 / 5.0 + 32));
break;
case 2:
num = takeNum();
displayNum(num, ((num - 32) * 5 / 9.0));
break;
default:
flag = false;
}
}
catch(InputMismatchException e){
System.err.println("Error: Input is of an incorrect datatype!");
input.nextLine();
}
}

}
}
static double takeNum() throws InputMismatchException {
System.out.print("Please insert number: ");
return new Scanner(System.in).nextDouble();
}

static void displayNum(double source, double conv){
System.out.printf("%.2f\t->\t%.2f\n", source, conv);
}
}