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

当前位置:首页 > 《面向对象程序设计》上机编程题 附答案(修)

《面向对象程序设计》上机编程题 附答案(修)

  • 62 次阅读
  • 3 次下载
  • 2025/4/30 22:40:35

2013-2014学年《面向对象程序设计》上机编程题

安徽财经大学管理科学与工程学院

1、编写程序实现对输入的3个整数,按照从大到小的顺序输出。 程序如下:

import java.util.Scanner; public class cxddsc {

public static void main(String args[]){ Scanner input=new Scanner(System.in); int a,b,c,t;

System.out.print(\输入第一个数:\); a=input.nextInt();

System.out.print(\输入第二个数:\); b=input.nextInt();

System.out.print(\输入第三个数:\); c=input.nextInt();

if(b>a){ t=a;a=b;b=t; }

if(c>a){ t=a;a=c;c=t; }

if(c>b){ t=b;b=c;c=t; }

System.out.printf(\从大到小输出为:===\,a,b,c); } }

2、编写程序,输入一个字符,判断它是否为小写字母,如果是,将它转换成大写字母,否则,不转换。 import java.util.Scanner;

public class bdxx {

public static void main(String args[]){ Scanner input=new Scanner(System.in);

System.out.print(\输入一个字符:\); char c=input.next().charAt(0); if(c>='a'&&c<='z'){ c=(char)(c-32);

System.out.printf(\,c); }

else if(c>='A'&&c<='Z'){

System.out.println(\这是一个大写字母!不转换!\); } } }

3、编写程序,对输入的3个正数,判断能否构成一个三角形。 import java.util.Scanner;

public class sjx {

public static void main(String args[]){ Scanner input=new Scanner(System.in); int a,b,c;

System.out.print(\输入第一个数:\); a=input.nextInt();

System.out.print(\输入第二个数:\); b=input.nextInt();

System.out.print(\输入第三个数:\); c=input.nextInt();

if((a+b)>c&&(a-b)0&&c>0&&b>0) System.out.println(\这三个数能构成三角形!\); else

System.out.println(\这三个数不能构成三角形!\); } }

4、编写程序,输入一个0~999之间的数,判断输入的数是几位数? import java.util.Scanner;

public class jws {

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

System.out.print(\请输入一个0~999之间的数:\); a=input.nextInt(); if(a<0||a>999)

System.out.print(\输入错误,请重新输入0~999之间的数:\); else

if(a/100!=0)System.out.print(\这是个三位数!\); else if(a/10!=0)System.out.print(\这是一个两位数!\); else System.out.print(\这是一个一位数!\); } }

5、编写程序,对输入的一个整数,按每个数字的相反顺序输出该数。 import java.util.Scanner;

public class fz {

public static void main(String args[]){ int a,b;

Scanner input=new Scanner(System.in); System.out.print(\请输入一个整数:\); a=input.nextInt(); while(a!=0){ b=a;

System.out.printf(\,b); a=a/10; } } }

6、用while 循环,计算1~100 之间所有5 的倍数的数之和。 public class bs {

public static void main(String args[]){ int i=1,sum=0; while(i<=100)

{if(i%5==0)sum=sum+i; i++; }

System.out.printf(\之间所有5的倍数的数之和为sum=%d\,sum); } }

7、编写程序,给定一个学生成绩,给出相应等级:

90~100 优秀 80~89 良好 70~79 中等 60~69 及格 0~59 不及格

import java.util.Scanner; public class cj {

public static void main(String args[]){ int a; String b;

Scanner input=new Scanner(System.in); System.out.print(\请输入一个学生的成绩:\);

a=input.nextInt(); switch(a/10){ case 10:

case 9:b=\优秀\;break; case 8:b=\良好\;break; case 7:b=\中等\;break; case 6:b=\及格\;break; default:b=\不及格\; }

System.out.printf(\这位同学的成绩等级为%s\,b); } }

8、编写程序,输出0~100之间的所有素数。 public class sushu {

public static void main(String args[]){ for (int n=1;n<=100;n++){ boolean b = true; if (n != 1 ){

for (int i = 2; i < n; i++){ if (n % i == 0){ b = false; break; } } } if (b){

System.out.println(n + \是素数\); } } } }

9、使用循环语句,输出如下的图形:

# # # # # # # # # # # # # # # # # # # # # # # # #

public class huaxin {

public static void main(String args[]){

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

2013-2014学年《面向对象程序设计》上机编程题 安徽财经大学管理科学与工程学院 1、编写程序实现对输入的3个整数,按照从大到小的顺序输出。 程序如下: import java.util.Scanner; public class cxddsc { public static void main(String args[]){ Scanner input=new Scanner(System.in); int a,b,c,t; System.out.print(\输入第一个数:\); a=input.nextInt(); System.out.print(\输入第二个数:\); b=input.nextInt(); System.out.print(\输入第三个数:\

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价: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