0
我是一个初学者,试图编写一个java代码来生成输出数字,这个输出数字是2和5的主要因素。Java“For”循环输出重复
例如,如果输入是,那么输出应该是。 但是,每当我打印我的输出,结果将是2 5 4 5 8 5.
请咨询我出错的地方。 谢谢
import java.util.Scanner;
class twofive {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter n:");
int n = sc.nextInt();
double num = 0;
double num2 = 0;
for (int i = 1; (((Math.pow(2,i))<= n) || ((Math.pow(5,i)) <=n) || (((Math.pow(2,i))<= n) && ((Math.pow(5,i)) <=n))) ; i++) {
if ((Math.pow(2,i)) <= n)
num = (Math.pow(2,i));
int convert = (int) num;{
System.out.print(convert + " ");
}
if ((Math.pow(5,i)) <= n)
num2 = (Math.pow(5,i));
int convert2 = (int) num2;
{System.out.print(convert2 + " ");
}
}
}
}
8的整数*因子是** 1 2 4 8 **。 8的* prime *分解是* 2 2 2 *或* 2^3 *。你的代码做了其他的事情:它会产生小于或等于给定整数的2和5(以及素数2和5)的所有*组合。 –