-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4_main.java
More file actions
29 lines (28 loc) · 696 Bytes
/
Copy pathQ4_main.java
File metadata and controls
29 lines (28 loc) · 696 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 lab8;
import java.util.Scanner;
public class Q4_main {
static String x;
static String y;
static void comp(String x, String y) throws Exception
{
int a = Integer.parseInt(x);
int b = Integer.parseInt(y);
System.out.println("Addition is: " + (a + b));
System.out.println("Subtration is " + (a - b));
}
public static void main(String[] args)
{
Scanner ts = new Scanner(System.in);
System.out.println("First Character:");
x = ts.nextLine();
System.out.println("Second Character:");
y = ts.nextLine();
ts.close();
try {
comp(x, y);
}
catch (Exception e) {
System.out.println("Alphanumeric values are not allowed.");
}
}
}