云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 竞赛java编程题50题(有答案)

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

  • 62 次阅读
  • 3 次下载
  • 2025/6/22 23:10:10

}

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题(有答案) 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

} class getChar{ public char getChar() { Scanner s = new Scanner(System.in); String str = s.nextLine(); char ch = str.charAt(0); if(ch'Z') { System.out.println(\输入错误,请重新输入\ ch=getChar(); } return ch; } } 【程序27】 题目:求100之内的素数 //使用除sqrt(n)的方法求出的素数不包括2和3 public class lianxi27 { public

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com