Table of contents
1.1 Operation process (thought)
2. Determine how many prime numbers there are between 100-200
1.1 Operation process (thought)
foreword
1. Due to multiple reasons, this blog post consists of two code programs. If you have a choice, you can quickly search in the directory;
2. This pop-up window interface can realize one-use functions according to simple requirements. At the same time, custom settings can be realized;
3. The system can only run on the console (eclipse and other versions), and needs to be matched with jdk8 and other environments;
4. Here is a special note, if the package name of the complete code to be pasted is inconsistent with mine, the program is specified to be unable to run, please change it manually;
5. This code was written by me when I was in school. There are some places that have not been perfectly implemented. Please forgive me and give me more advice!
提示:以下是本篇文章正文内容,下面案例可供参考
1. Realize the example of decomposing positive integers into prime factors by inputting 100 and outputting 100=2×2×5×5
1.1 Operation process (thought)
This is a program code that defines the parameter content in Java, and then realizes the input 100 output 100=2×2×5×5 program code by decomposing the prime factor of the positive integer. The specific setting idea is as follows:
1.2 code snippet
The code is as follows (example):
package 程序基础;
public class 正整数分解质因数 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int num=100;
int k=2;
System.out.print(num+"=");
while (num>k) {
if (num%k==0){
System.out.print(k+"×");
num=num/k;
}
if (num%k!=0){
k++;
}
}
System.out.println(k);
}
}
1.3 run screenshot
The code is as follows (example):
2. Determine how many prime numbers there are between 100-200
1.1 Operation process (thought)
This is a program code that defines the parameter content in Java, and then judges how many prime numbers there are between 100-200 through a loop. The specific setting idea is as follows:
1.2 code snippet
The code is as follows (example):
package 程序基础;
public class 判断100-200之间有多少个素数并输出所有素数 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
int count=0;
for (int i=100;i<=200;i++){
boolean a= true;
for (int j=2;j*j<=i;j++){
if (i%j==0){
a=false;
break;
}
}
if (a){
System.out.print(i + "\t");
count++;
if (count % 5 == 0) {
System.out.println();
}
}
}}}
1.3 run screenshot
The code is as follows (example):