forked from 20ayan/Hacktoberfest22
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd2nos.java
More file actions
43 lines (43 loc) · 708 Bytes
/
add2nos.java
File metadata and controls
43 lines (43 loc) · 708 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//add two numbers using oop approach
import java.io.*;
import java.util.Scanner;
class Add
{
private int a,b,c;
void getdata(int x,int y)
{
a=x;
b=y;
}
void addition()
{
c=a+b;
}
void print()
{
System.out.println("Addition of 2 numbers is: "+c);
}
}
class add2nos
{
public static void main(String args [])
{
int m,n,sum;
try
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number");
m=sc.nextInt();
System.out.println("Enter second number");
n=sc.nextInt();
Add p = new Add();
p.getdata(m,n);
p.addition();
p.print();
}
catch (Exception e)
{
System.out.println("Error!!");
}
}
}