-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoIntMain.java
More file actions
39 lines (39 loc) · 809 Bytes
/
Copy pathTwoIntMain.java
File metadata and controls
39 lines (39 loc) · 809 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
/* A java progrma to create a class having two fields a and b of integer type and write methods to read, print and calculate the sum of fields */
import java.util.Scanner;
class TwoInt
{
int a,b;
void setValues(int x,int y)
{
a = x;b = y;
}
void getValues()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter A = ");
a = sc.nextInt();
System.out.print("Enter B = ");
b = sc.nextInt();
}
void putValues()
{
System.out.println("A = "+a+"\nB = "+b);
}
int sum()
{
return(a+b);
}
}
class TwoIntMain
{
public static void main(String[] args)
{
TwoInt ti = new TwoInt();
ti.setValues(10,20);
ti.putValues();
System.out.print("Sum = "+ti.sum());
ti.getValues();
ti.putValues();
System.out.println("Sum = "+ti.sum());
}
}