0
Follow
0
View

# java quality factor complements the code

darren895 注册会员
2023-02-28 02:18
cuiping3210 注册会员
2023-02-28 02:18

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > the following is a complete Java code, can be a positive integer is decomposed into the product of prime factors, and the output according to the requirement:

``````import java.util.Scanner;

public class Main {

public static void main(String[] args) {

int n;

Main pf = new Main();

pf.printPrimeFactor(n);
}

void printPrimeFactor(int n) {  //求整数n的质因子，按要求输出
System.out.print(n + "="); //输出原数n

int i = 2; //从2开始寻找因子
while (i <= n) {
if (n % i == 0) { //如果n能够被i整除
System.out.print(i); //输出i
n /= i; //将n除以i，以便继续寻找因子
if (n != 1) { //如果n不等于1，则继续输出乘号
System.out.print("*");
}
} else { //否则i加1
i++;
}
}
}

if (n <= 1) { //小于等于1的数不是质数
return 0;
}
for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) { //如果能够被整除，不是质数
return 0;
}
}
return 1; //是质数
}
}

``````

The program runs as follows:

Input:

``````90
``````

Output:

``````90=2*3*3*5

``````
qznxcyp 注册会员
2023-02-28 02:18

Try this code

``````import java.util.Scanner;

public class Main {

csharp
Copy code
public static void main(String[] args) {

int n;

Main pf = new Main();

pf.printPrimeFactor(n);

}

void printPrimeFactor(int n) {  //求整数n的质因子，按按要求输出

System.out.print(n + "=");

int i = 2;

while (i <= n) {

if (n % i == 0) {

System.out.print(i);

n = n / i;

if (n != 1) {

System.out.print("*");

}

} else {

i++;

}

}

}

if (n <= 1) {

return 0;

}

for (int i = 2; i <= Math.sqrt(n); i++) {

if (n % i == 0) {

return 0;

}

}

return 1;

}
}

``````
duhuafeng2006 注册会员
2023-02-28 02:18

gpt generation bug, has been changed

cz4141 注册会员
2023-02-28 02:18
); printPrimeFactor(n); } } isPrimeNumber ( int n) { // 判断n是否为质数，返回1为质数，返回0为非质数 int i = 2 ; while (i <= Math.sqrt(n)) { if (n % i == 0 ) { return 0 ; } i++; } return 1 ; } } .
< !- - - - - >
cyflove23 注册会员
2023-02-28 02:18

This answer is quoted from ChatGPT

``````public class Main {
public static void main(String[] args) {
int n;
Main pf=new Main();
pf.printPrimeFactor(n);
}

void printPrimeFactor(int n){  //求整数n的质因子，按按要求输出
int i=2;
System.out.print(n+"=");
while(i<=n){
System.out.print(i);
n=n/i;
if(n!=1){
System.out.print("*");
}
}else{
i++;
}
}
System.out.println();
}
int flag=1;
for(int i=2;iif(n%i==0){
flag=0;
break;
}
}
return flag;
}
}

``````
danyuanjh 注册会员
2023-02-28 02:18
< div class = "md_content_show e397 data - v - 3967" = "" >

hello, excuse me n %! What does it mean that i(MISSING)==0?

donglei55 注册会员

Publish Time
2023-02-28 02:18
Update Time
2023-02-28 02:18