-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpi.java
50 lines (46 loc) · 1.5 KB
/
pi.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
43
44
45
46
47
48
49
50
/**
* Write a description of class pi here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.math.BigInteger;
public class pi
{
public static void main (double a,double b)
{
try{
double c=a/b;
String str=" ";int n=0,p=0;
String s=Double.toString(c);
for(int i=0;i<s.length();i++)
if(s.charAt(i)=='.')
str=s.substring(n=i+1);
for(int i=0;i<=str.length()-1;i++)
{
for(int j=i+1;j<=str.length()-1;j++)
{
if(str.charAt(i)==str.charAt(j)&&str.charAt(i+1)==str.charAt(j+1))
{
System.out.println("The number "+s.substring(0,n+j)+" is recurring after "+str.substring(i,j));
p=1;
break;
}
}
if(p==1)
break;
}
}
catch(StringIndexOutOfBoundsException e) {
//BigInteger x = new BigInteger(Double.toString(a));
//BigInteger y = new BigInteger(Double.toString(b));
BigInteger c = new BigInteger(Double.toString(a/b));
/*BigInteger bi2 = new BigInteger("3039768898793547264523745379249934");
BigInteger bigSum = bi1.add(bi2);
BigInteger bigProduct = bi1.multiply(bi2);
System.out.println("Sum : " + bigSum);
System.out.println("Product : " + bigProduct);*/
System.out.println("The number "+c+" is not recurring");
}
}
}