手机版

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

时间:2025-07-07   来源:未知    
字号:

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文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)