forked from sourabh48/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrational.java
More file actions
65 lines (63 loc) · 1.12 KB
/
rational.java
File metadata and controls
65 lines (63 loc) · 1.12 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
65
import java.io.*;
class rational
{
int num,den,r;
void setdata()
{
DataInputStream dis=new DataInputStream(System.in);
try
{
System.out.println("Enter the Denominator");
num=Integer.parseInt(dis.readLine());
System.out.println("Enter the Numerator");
den=Integer.parseInt(dis.readLine());
}
catch(Exception e)
{}
}
boolean is_equal(rational r)
{
if((num==r.num)&&(den==r.den))
{
return true;
}
else
{
return false;
}
}
rational add(rational r)
{
r.num=(num*r.den)+(r.num*den);
r.den=(den*r.den);
return r;
}
rational div()
{
r.num=(num*r.den);
r.den=(den*r.num);
return r;
}
void display()
{
}
public static void main(String args[])
{
rational r1=new rational();
rational r2=new rational();
r1.setdata();
r2.setdata();
rational r= new rational();
r=r1.div(r2);
System.out.println("Division of 2 rationals is");
r.show();
boolean b=r1.is_equal(r2);
if(b==true)
System.out.println("Both are Equal numbers");
else
System.out.println("Both are Unequal");
r=r1.add(r2);
System.out.println("Addition of two rationals is:");
r2.show();
}
}