解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
String str="";
pd(n,str);
}
private static void pd(int n, String str) {
// TODO Auto-generated method stub
if(str.length()==n)
System.out.println(str);
else {
for(int i=1;i<10;i++) {
//System.out.println(str);
if(pd1(Integer.parseInt(str+i)))
pd(n,str+i);
}
}
}
private static boolean pd1(int m) {
// TODO Auto-generated method stub
int t=0;
if(m<2)
return false;
for(int j=2;j*j<=m;j++) {
if(m%j==0) {
t=1;
break;
}
}
if(t==0)
return true;
else
return false;
}
}
0.0分
0 人评分
C二级辅导-计负均正 (C语言代码)浏览:593 |
C语言训练-斐波纳契数列 (C语言代码)浏览:785 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1118 |
K-进制数 (C++代码)浏览:857 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:534 |
A+B for Input-Output Practice (C++代码)浏览:609 |
Pascal三角 (C语言代码)浏览:1188 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:758 |
众数问题 (C语言代码)浏览:830 |
【金明的预算方案】 (C++代码)浏览:843 |