最新JAVA编程题全集(50题及答案) 2(15)
时间:2025-04-20
时间:2025-04-20
else if(ch2 == 'A') {System.out.println("Saturday"); }
else {System.out.println("无此写法!");
}
};
break;
default:System.out.println("无此写法!");
}
}
}
class getChar{
public char getChar() {
Scanner s = new Scanner(System.in);
String str = s.nextLine();
char ch = str.charAt(0);
if(ch<'A' || ch>'Z') {
System.out.println("输入错误,请重新输入");
ch=getChar();
}
return ch;
}
}
【程序27】
题目:求100之内的素数
//使用除sqrt(n)的方法求出的素数不包括2和3
public class lianxi27 {
public static void main(String[] args) {
boolean b =false;
System.out.print(2 + " ");
System.out.print(3 + " ");
for(int i=3; i<100; i+=2) {
for(int j=2; j<=Math.sqrt(i); j++) {
if(i % j == 0) {b = false;
break;
} else{b = true;}
}
if(b == true) {System.out.print(i + " ");}
}
}
}
//该程序使用除1位素数得2位方法,运行效率高通用性差。
public class lianxi27a {
public static void main(String[] args) {
int[] a = new int[]{2, 3, 5, 7};
上一篇:JRC电子海图
下一篇:2012年出口关税税率表