竞赛java编程题50题(有答案)(4)

2019-05-17 13:11

case 'F':

System.out.println(\ break; case 'T': {

System.out.println(\请输入星期的第二个字母:\ char ch2 = tw.getChar();

if(ch2 == 'U') {System.out.println(\ else if(ch2 == 'H') {System.out.println(\ else {System.out.println(\无此写法!\ } }; break; case 'S': {

System.out.println(\请输入星期的第二个字母:\ char ch2 = tw.getChar();

if(ch2 == 'U') {System.out.println(\

else if(ch2 == 'A') {System.out.println(\ 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};

for(int j=0; j<4; j++)System.out.print(a[j] + \ boolean b =false;

for(int i=11; i<100; i+=2) { for(int j=0; j<4; j++) { if(i % a[j] == 0) {b = false; break; } else{b = true;} }

if(b == true) {System.out.print(i + \ } } }

【程序28】

题目:对10个数进行排序 import java.util.*; public class lianxi28 {

public static void main(String[] args) { Scanner s = new Scanner(System.in); int[] a = new int[10];

System.out.println(\请输入10个整数:\ for(int i=0; i<10; i++) { a[i] = s.nextInt(); }

for(int i=0; i<10; i++) { for(int j=i+1; j<10; j++) { if(a[i] > a[j]) { int t = a[i]; a[i] = a[j]; a[j] = t; } } }

for(int i=0; i<10; i++) { System.out.print(a[i] + \ } }

}

【程序29】

题目:求一个3*3矩阵对角线元素之和 import java.util.*; public class lianxi29 {

public static void main(String[] args) { Scanner s = new Scanner(System.in); int[][] a = new int[3][3];

System.out.println(\请输入9个整数:\ for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { a[i][j] = s.nextInt(); } }

System.out.println(\输入的3 * 3 矩阵是:\ for(int i=0; i<3; i++) { for(int j=0; j<3; j++) {

System.out.print(a[i][j] + \ }

System.out.println(); }

int sum = 0;

for(int i=0; i<3; i++) { for(int j=0; j<3; j++) {


竞赛java编程题50题(有答案)(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2财务管理基本价值观念练习

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

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