最新JAVA编程题全集(50题及答案) 2(15)

时间: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};

最新JAVA编程题全集(50题及答案) 2(15).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219