Public class Sushu1 {
Public static void main (String [] args) {
//TODO Auto - generated method stub
Int [] data;
data=https://bbs.csdn.net/topics/new int [1000].
System. The out. Println (" primes within 1 ~ 1000 as shown in the following ");
InputData (data);
CalcPrimeNum (data);
PrintPrimeNum (data);
}
//definition method 1: input 1 ~ 1000 data (data assignment method)
Public static void InputData (int [] data) {
for(int i=0; i
Data [I]=I + 1;
}
}
//definition method 2: remove all the non-prime number in the input data
Public static void CalcPrimeNum (int [] data) {
Int I, j, temp.
Data [0]=0;
for(i=1; i
If (data [j].=0) {
Temp=data [j] % data [I];
If (temp==0) {
Data [I]=0;
}
}
}
}
}
//definition method 3: a line of print format to print all the primes of 10 prime
Public static void PrintPrimeNum (int [] data) {
Int the items=0;
for(int i=0; i
System. The out. Printf (" % 5 d, "data [I]);
Items++;
If (10 items %==0)
System.out.println();
}
}
}
}
CodePudding user response:
Wrong, look at thePublic class Sushu1 {
Public static void main (String [] args) {
//TODO Auto - generated method stub
Int [] data;
data=https://bbs.csdn.net/topics/new int [1000].
System. The out. Println (" primes within 1 ~ 1000 as shown in the following ");
InputData (data);
CalcPrimeNum (data);
PrintPrimeNum (data);
}
//definition method 1: input 1 ~ 1000 data (data assignment method)
Public static void InputData (int [] data) {
for(int i=0; i
}
}
//definition method 2: remove all the non-prime number in the input data
Public static void CalcPrimeNum (int [] data) {
Int I, j, temp.
Data [0]=0;
for(i=1; i
If (data [j].=0) {
Temp=data [j] % data [I];
If (temp==0) {
Data [I]=0;
}
}
}
}
}
//definition method 3: a line of print format to print all the primes of 10 prime
Public static void PrintPrimeNum (int [] data) {
Int the items=0;
for(int i=0; i
System. The out. Printf (" % 5 d, "data [I]);
Items++;
If (10 items %==0)
System.out.println();
}
}
}
}