我想做一个程序,用户输入2个数字,然后程序给出这个间隙中的头号码。头号码算法
- “头”号是可以除以它的分频器总数的数字。例如(1,2,3,4,6,8,12,24)所有这些数字可以除以24。是8个数字,然后24可以除以8.所以我们可以说24是一个头号码。*
我认为第二个循环有一个错误,但我不明白它在哪里。
import java.util.Scanner;
public class tauNumber {
public static void main(String [] args){
int start=0,stop=0,count=0;
Scanner input =new Scanner(System.in);
System.out.println("Please enter first number: ");
start=input.nextInt();
System.out.println("Please enter last number: ");
stop=input.nextInt();
for(int i=0+start;i<=stop;i++){
for(int j=1;j<=start;j++){
if(i%j==0){
count++;
}
}
if(start/count==0){
System.out.println(i+" is a tau number");
}
}
}
}
什么是“头数”到底是什么?但我的猜测是,你忘记在for循环开始时将'count'重新初始化为0。 – Tunaki
@Tunaki [显然是一个常数](http://tauday.com/tau-digits)像'e'和'pi'。 – px06
@ px06其实,[它是一个可以被除数除数的数字](http://mathworld.wolfram.com/RefactorableNumber.html)。 Tau也是2 * pi,但在这里不同。 – Tunaki