我正在寻找重复序列的十进制输出,我不能得到它输出正确:/(我可能会回答有点晚,抱歉)输出语句
例如。
N = 1,d = 7
七分之一= 0.142857142857142857 ...
输出= 0。(142857)
或
N = 45,d = 56
56分之45= 0.803571428571428571428
输出= 0.803(871428)
这里是我下面的代码:
import java.util.*;
public class RepeatingSequence{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter N,D: ");
double numerator = in.nextInt();
double denominator = in.nextInt();
double quotient = numerator/denominator;
String number = "" + quotient;
char n = number.charAt(0);
int j = 2;
int z = 0;
String output = "";
char[] index = new char[100];
for (int i = 3; (i < number.length()) && (number.charAt(j) >= number.charAt(i) || (number.charAt(j) <= number.charAt(i))); i++){
index[z] = number.charAt(z);
index[j] = number.charAt(j);
index[i] = number.charAt(i);
if (index[i] != index[z]){
System.out.print("(" + index[i] + ")");
}
}
}
}
你应该怎么做? I = 3?我会在搜索循环之前填充你的数组(或者只使用string.charAt) – eckes 2014-12-04 00:34:49
这是一个比它最先出现的更难的问题。这是一项家庭作业吗? – ajb 2014-12-04 00:34:52
我= 3将确定在(2)的字符?我认为那是我打算做的目的。 - eckes @ajb - 通过这并不是强制性的。但我需要它来获得额外的学分。 – 2014-12-04 00:36:58