-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrecurring_number_or_not.java
39 lines (37 loc) · 1.03 KB
/
recurring_number_or_not.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
/**
* Write a description of class recurring_number_or_not here.
*
* @author (Swapnanil)
* @version (a version number or a date)
*/
public class recurring_number_or_not
{
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) {
System.out.println("The number "+(a/b)+" is not recurring");
}
}
}