使用栈降序显示前50个素数(质数)
Stack stack=new Stack();
stack.push(2);
int i=3;
while(stack.size()<51){
boolean bool=false;
for(int j=2;j<=Math.sqrt(i);j++){
if(i%j==0){
bool=true;
}
}
if(bool==false) {
stack.push(i);
}
i++;
}
while(!stack.empty())
System.out.println(stack.pop());