-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCalc.java
More file actions
64 lines (60 loc) · 1.59 KB
/
Calc.java
File metadata and controls
64 lines (60 loc) · 1.59 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
57
58
59
60
61
62
63
64
import java.io.File;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Calc {
static Scanner scanner= new Scanner(System.in);
static int firstNo=0;
static int secondNo = 0;
static int result = 0;
static void takeFirstNo(){
try{
System.out.println("Enter the First No");
firstNo = scanner.nextInt(); // throw new InputMismatchException();
}
catch(InputMismatchException object){
System.out.println("Only Number Allowed and U Enter Something else...");
scanner.nextLine();
takeFirstNo();
}
}
static void divide(){
try{
result = firstNo/ secondNo;
}
catch(ArithmeticException e){
System.out.println("U Divide a Number with Zero ");
takeSecondNo();
divide();
}
}
static void takeSecondNo(){
try{
System.out.println("Enter the Second No");
secondNo = scanner.nextInt(); // throw new InputMismatchException();
}
catch(InputMismatchException object){
System.out.println("Only Number Allowed and U Enter Something else...");
scanner.nextLine();
takeSecondNo();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//c:\\abcd\\xyz\\abcd.txt
File file = new File("/Users/amit/Documents/FileHandlingTestingCase/abcd1.txt");
try {
file.createNewFile();
System.out.println("File Created...");
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Unable to Create File...");
}
int p = 10/0;
takeFirstNo();
takeSecondNo();
divide();
System.out.println("Result is "+result);
scanner.close();
}
}