Last active
December 31, 2015 14:38
-
-
Save mperk/8001126 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
/** | |
* @author mperk | |
* | |
*/ | |
//Virgülden sonra tekrar eden kısmı ekrana yazdıran kod. | |
//Decimal number; section of repeated | |
public class Main { | |
public static void main(String[] args) { | |
BigInteger number = new BigInteger("0769230769230769230"); | |
ArrayList<Integer> digList = new ArrayList<Integer>(); | |
MyCycle(number, digList); | |
} | |
private static void MyCycle(BigInteger number, ArrayList<Integer> digList) { | |
if (digList.size() == 0) { | |
digList.add(number.mod(BigInteger.valueOf(10)).intValue()); | |
// number'ın sonundaki rakamı aldım. | |
// last number | |
number = number.divide(BigInteger.valueOf(10)); | |
MyCycle(number, digList); | |
} else { | |
int lastValue = number.mod(BigInteger.valueOf(10)).intValue(); | |
if (lastValue == digList.get(0)) { | |
int ex = (int) Math.pow(10, digList.size()); | |
int temp = number.mod(BigInteger.valueOf(ex)).intValue(); | |
// number'ın bana lazım olan rakamlarını yakalıyorum. | |
// number is cut to the size of directory | |
int i = 0; | |
while (i < digList.size()) { | |
if (digList.get(i) == temp % 10) { | |
temp = temp / 10; | |
if (digList.size() - 1 == i) { | |
// tekrar bulundu. | |
// repeat number is find | |
System.out.println("Section of repeated:"); | |
//System.out.println(digList); | |
Collections.reverse(digList); | |
System.out.println(digList); | |
} | |
i++; | |
} else { | |
digList.add(number.mod(BigInteger.valueOf(10)) | |
.intValue()); | |
number = number.divide(BigInteger.valueOf(10)); | |
MyCycle(number, digList); | |
return;// bunun sebebi kod recursive yapıdan tam | |
// çıkmıyor. | |
// number'ın son rakamı diziye ekleniyor ve | |
// number'dan o rakam atılıyor. | |
// The last number was added to the array | |
// And The last number was cut | |
} | |
} | |
} else { | |
digList.add(number.mod(BigInteger.valueOf(10)).intValue()); | |
number = number.divide(BigInteger.valueOf(10)); | |
if (number.intValue() != 0) //tekrar yoksa (if no repeated) | |
MyCycle(number, digList); | |
// number'ın son rakamı diziye ekleniyor ve | |
// number'dan o rakam atılıyor. | |
// The last number was added to the array | |
// And The last number was cut | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment