|
宁波大红鹰学院 2018-2019学年第一学期 2015级专科计算机应用技术专业《Java高级编程》 毕业补考考试试卷 考核方式:大作业 题目一:程序阅读题(每题5分,总共40分) 要 求:阅读以下程序,完成程序填空并运行程序结果。 1、以下程序最终运行的结果i是_____2______. class MaxShuzu { public static void main(String args[]) { int i=1; int j=i++; if((i>++j)&&(i++==j)){ i+=j; } } } 2、以下程序最终运行的结果是_____168_______。 class MaxShuzu { public static void main(String args[]) { int x[]={125,21, 5, 168, 98}; int max=x[0]; for(int i=1;i<5;i++){ if(x>max) max=x; } System.out.println(max); } } 3、以下程序的作用是什么? class Breakexe { publicstatic void main(String args[]) { intsum=0,n=1; while(true) { sum+=n; if(sum>=100) break; n++; } System.out.println(n); } } 答:______求n第多少次总和大于100__________________ ________________________________________________ 4、 public class star { public static voidmain(String[] args) { int i,j; for(i=0;i<5;i++){ for(j=0;j<=i;j++) System.out.print("*"); System.out.println(); } } } 输出结果:____________ * * * * * * * * * * * * * ** ________________________________________________ 5、阅读以下程序 public classExcise73 { public static void main(String[] args) { double p1=3,p2=3.5; double sum; System.out.println("请输入订购数量:"); Scanner in=new Scanner(System.in); int num=in.nextInt(); if(num>200) sum=num*p1; else sum=num*p2; System.out.println("总价是:"+sum); } } 当输出值为300时,输出__________900__________________________________________ 6、阅读以下程序: public class abc { public static void main(String args[ ]) { int i, s = 0 int a[] = { 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120 }; for ( i = 0 i< a.length i++ ) if (i % 3 == 0) s += a; System.out.println("s=" + s); } } 输出结果:__________s=260____________________________________________________ 7、阅读以下程序: public class TestArray { publicstatic void main(String args[ ]){ int i , j ; int a[ ] = { 5,9,6,8,7}; for ( i = 0 ; i < a.length-1; i ++ ) { int k = i; for ( j = i ; j < a.length ; j++ ) if ( a[j]<a[k] ) k =j; int temp =a; a = a[k]; a[k] = temp; } for ( i =0 ; i<a.length; i++ ) System.out.print(a+" "); System.out.println( ); } } 输出结果:___________ 5 6 7 8 9___________________________ 8、阅读以下程序: class ScoreExe { public static void main(String args[]) { int score=75; switch(score<0||score>100) { case 0: case 1: case 2: case 3: case 4: case 5: System.out.println("等级为E-不及格。"); break; case 6: System.out.println("等级为D-及格。");break; case 7: System.out.println("等级为C-可。");break; case 8: System.out.println("等级为B-良好。");break; case 9: case 10: System.out.println("等级为A-优秀。"); } } } } 输出结果:_______________编译错误:swtich不支持boolean表达式条件______________________________________________ 题目二:程序设计题(每题20分,总共60分) 1. 根据题目描述编写程序: 编写程序,完成一个计算器,该计算器能够完成对输入两个数的加、减、乘、除运算。加减乘除四个运算符从键盘中输入。 2. 按要求完成如下程序: 编程实现:提示用户输入用户名和密码,如果用户名和密码都正确,则提示正确,如果用户名输入错误,则提示用户名错误,如果密码输入错误,则提示密码错误,输入三次程序退出。 3. 我国古代数学家张丘建成在《算经》中出了一道"百钱买百鸡"的问题,题意是:五文钱可以买一只公鸡,3文钱可以买一只母鸡,1文钱可以买3只雏鸡,现在用100文钱买一百只鸡,那么各有公鸡、母鸡、雏鸡多少只? 设计程序实现计算。 作业上交要求: 1、作业上交截止时间2018年9月17日 2、作业上交内容:(1)包含所有程序的源文件(.java)的项目文件夹;(2)将文件打包以“班级+姓名+学号”的方式命名。 下载地址: |