第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2026/8/31 14:03:02 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

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题(有答案) 的文档
竞赛java编程题50题(有答案).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c28ejy03u5k6m3qp9y5sf_5.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top