-
Notifications
You must be signed in to change notification settings - Fork 3
/
Poly.java
42 lines (34 loc) · 1.11 KB
/
Poly.java
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
import java.util.*;
class Polynomial
{
int coeff, value;
Polynomial(int coeff,int value)
{
this.coeff = coeff;
this.value = value;
}
Polynomial add(Polynomial obj1)
{
int reult_coeff = obj1.coeff+ coeff;
int result_value = obj1.value + value;
Polynomial result = new Polynomial(reult_coeff,result_value);
return result;
}
}
public class Poly {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of the coefficent and the constant of the first polynomial");
int coeff_1 = sc.nextInt();
int val_1 =sc.nextInt();
Polynomial p1= new Polynomial(coeff_1, val_1);
System.out.println("Enter the value of the coefficent and the constant of the second polynomial");
int coeff_2 = sc.nextInt();
int val_2 =sc.nextInt();
Polynomial p2= new Polynomial(coeff_2, val_2);
Polynomial p3 = p1.add(p2);
System.out.println("The resultant coefficent is "+p3.coeff+"x+"+p3.value);
sc.close();
}
}