Created
September 3, 2017 13:00
-
-
Save mizucoffee/458af80a174dbaa571055346d21a4ed5 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.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.math.BigDecimal; | |
import java.math.RoundingMode; | |
import java.util.regex.Pattern; | |
public class Main { | |
private static final String CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
public static void main(String[] args) throws Exception { | |
String data = "12.345"; | |
int base = 10; | |
if(base > 62){ | |
System.err.println("62進数までです"); | |
System.exit(1); | |
} | |
int integer = Integer.parseInt(data.split(Pattern.quote("."))[0]); | |
BigDecimal few = new BigDecimal("0." + data.split(Pattern.quote("."))[1]); | |
String newBase = ""; | |
for(int i = 0;i < 1200;i++){ | |
few = few.multiply(new BigDecimal(base)); | |
newBase += changeBase(few.intValue()); | |
few = few.subtract(new BigDecimal(few.intValue())); | |
} | |
// startPos 開始位置 | |
// length 桁数 | |
// checkPos 何回目 | |
boolean flag = true; | |
String num = ""; | |
tag: for(int startPos = 0;startPos < 100;startPos++){ | |
for(int length = 1;length <= 100;length++){ | |
flag = true; | |
for(int checkPos = 1;checkPos <= 10;checkPos++){ | |
if( !newBase.substring( startPos, startPos + length ).equals( newBase.substring( startPos + length * checkPos,startPos + length * checkPos + length ) )){ | |
flag = false; | |
break; | |
} | |
num = newBase.substring( startPos, startPos + length ); | |
} | |
if(flag){ | |
break tag; | |
} | |
} | |
} | |
System.out.println("整数部: " + data.split(Pattern.quote("."))[0]); | |
System.out.println("少数部: " + "." + data.split(Pattern.quote("."))[1]); | |
System.out.println("基 数: " + base); | |
System.out.println("=============================================================================================================================="); | |
System.out.println("計算結果: " + Integer.toString(integer,base) + "." + newBase.substring(0,100)); | |
System.out.println("循環節: " + num); | |
} | |
public static char changeBase(int num){ | |
return CHARS.charAt(num); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment