




已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、【必做题】1 输入一个数字,判断是一个奇数还是偶数if(i!=0)System.out.println(0);else if(i%2=1)System.out.println(奇数);else if(i%2=0)System.out.println(偶数);2 编写程序, 判断一个变量x的值,如果是1,输出x=1,如果是5,输出x=5,如果是 10,输出x=10,除了以上几个值,都输出x=none。(答案SwitchDemo.java)int x=1; switch(x) case 1: System.out.println(x=1); break; case 5: System.out.println(x=5); break; case 10: System.out.println(x=10); break; default: System.out.println(none); break; Switch说明 表达式的值只可以接受int、byte、char、short 型,不接受其他类型的值 不允许有重复的case取值 switch一旦碰到第一次case匹配,程序就会跳转到这个标签位置,开始顺序执行以后所有的程序代码,而不管后面的case条件是否匹配,直到碰到break语句为止3 判断一个数字是否能被5和6同时整除(打印能被5和6整除),或只能被5整除(打印能被5整除),或只能被6整除,(打印能被6整除),不能被5或6整除,(打印不能被5或6整除) System.out.println(*请输入一个整数*); Scanner scanner = new Scanner(System.in); int value = scanner.nextInt(); if (value % 5 = 0 & value % 6 = 0) System.out.println(输入的数字 + value + 能被5和6整除); else if (value % 5 = 0) System.out.println(输入的数字 + value + 能被5整除); else if (value % 6 = 0) System.out.println(输入的数字 + value + 能被6整除); else System.out.println(输入的数字不能被5或者6整除); 4输入一个年份,判断这个年份是否是闰年 int year=2012; if(year%4=0&year%100!=0|year%400=0) System.out.println(闰年); else System.out.println(不是闰年); 5输入一个0100的分数,如果不是0100之间,打印分数无效,根据分数等级打印A,B,C,D,Eint score = 999;if(score=90)System.out.println(A); else if(score=80)System.out.println(B);else if(score=70)System.out.println(C);else if(score=60)System.out.println(D);else if(score60)System.out.println(E);elseSystem.out.println(分数无效);6从命令行传入3个整数,求3个整数的和、积、最大值、最小值、平均值 int a = new int3; int max,min,add,pro,avr; for(int i=0;i3;i+) ai = Integer.valueOf(argsi); max = a0; min = a0; add = a0; pro = a0; for(int i=1;i3;i+) if(maxai) min = ai; add = add+ai; pro = pro*ai; avr = add/3; System.out.println(最大值 = +max); System.out.println(最小值 = +min); System.out.println(和 = +add); System.out.println(积 = +pro); System.out.println(平均值 = +avr);7试写一个三位数,从小到大排列,然后再从大到小排列。8输入三角形的三条边,判断是否是一个三角形,三角形的形状:等腰三角形,等边三角形,直角三角形,普通三角形,求出周长,如果是直角三角形,另外求出面积if(a=b & b=c)return(等边三角形);else if(a=b | b=c | a=c)return(等腰三角形);else if(a+bc & a+cb & b+ca)return(不等边三角形);9有一个不多于5位的正整数,求它是几位数,分别打印出每一位数字。import java.util.Scanner;public class Answer /* * param args the command line arguments */ public static void main(String args) / TODO code application logic here/ int num=12345; System.out.println(请输入一个不多于五位的正整数:); int num = input(); String str = String.valueOf(num); System.out.println(num + 的位数为: + str.length(); System.out.println(它的各位数分别为:); for (int i = 0; i = 0; i-) / System.out.println(str.charAt(i); System.out.print(str.charAt(i) + ); System.out.println(); private static int input() Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); return n; 10 在命令行输入年份,判断该年份是平年还是润年 int year=2012; if(year%4=0&year%100!=0|year%400=0) System.out.println(闰年); else System.out.println(不是闰年); 11 编写一个程序,计算邮局汇款的汇费。如果汇款金额小于100元,汇费为一元,如果金额在100元与5000元之间,按1%收取汇费,如果金额大于5000元,汇费为50元。汇款金额由命令行输入。public class Answer public static void main(String args) double A = Integer.parseInt(args0);double a = 0;if (A 5000) a = 50; else if (100 A) a = 1.0;System.out.println(汇费为: + a);12企业发放的奖金根据利润提成。利润低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润,求应发放奖金总数?public class Answer public static void main(String args) double x = 0,y = 0; System.out.print(输入当月利润(万):); Scanner s = new Scanner(System.in); x = s.nextInt(); if(x 0 & x 10 & x 20 & x 40 & x 60 & x 100) y = 20 * 0.175 + 40 * 0.08 + 40 * 0.015 + (x - 100) * 0.01; System.out.println(应该提取的奖金是 + y + 万);13输入三个整数x,y,z,请把这三个数由小到大输出import java.util.Scanner;public class Answer public static void main(String args) input fnc = new input(); int x=0, y=0, z=0; System.out.print(输入第一个数字:); x = fnc.input(); System.out.print(输入第二个数字:); y = fnc.input(); System.out.print(输入第三个数字:); z = fnc.input(); if(x y) int t = x; x = y; y = t; if(x z) int t = x; x = z; z = t; if(y z) int t = y; y = z; z = t; System.out.println( 三个数字由小到大排列为: +x + + y + + z);class inputpublic int input() int value = 0; Scanner s = new Scanner(System.in); value = s.nextInt(); return value;14 分别使用for循环,while循环,do循环求1到100之间所有能被3整除的整数的和。public class Answer public static void main(String args) /for部分int i, a = 0;for (i = 1; i = 100; i+) if (i % 3 = 0)a = a + i;System.out.println(a);/while 部分int i = 1, a = 0;while (i 101) if (i % 3 = 0) a = a + i;i+;System.out.println(a);/do while部分int i = 0, a = 0;do if (i % 3 = 0) a = a + i;i+; while (i 101);System.out.println(a);15 输出0-9之间的数,但是不包括5。public static void main(String args) for(int i=0;i= 90 ? A : x = 60 ? B :C; System.out.println(等级为:+grade); 注:将命令行参数赋给a(int型)使用的语句为: Int a = Integer.parseInt(args0);17 编写一个程序,从1计数到100,遇到3的倍数就替换为单词“hello”,遇到5的倍数就替换为单词“java”,既为3的倍数又是5的倍数则替换为单词“hellojava”,当是hellojava的时候换行,并输出。实现效果:public class Answer public static void main(String args) int i;for (i = 1; i 101; i+) if (i % 3 = 0 & i % 5 = 0) System.out.println(hellojava);else if (i % 3 = 0 & i % 5 != 0) System.out.print(hellot); else if (i % 5 = 0 & i % 3 != 0) System.out.print(javat); elseSystem.out.print(i + t);18 编写一个程序,求整数n的阶乘,例如5的阶乘是1*2*3*4*5import java.util.Scanner;public class Answer public static void main(String args) System.out.println(input:);Scanner in = new Scanner(System.in);int n = in.nextInt();int i = 0;int m = 1;for (i = 1; i = n; i+) m = m * i;System.out.println(n的階乘為:+m);19 编写一个程序,找出大于200的最小的质数public class Answer public static void main(String args) / TODO Auto-generated method stubfor (int i = 200; i 300; i+) boolean b = true;for (int j = 2; j i; j+) if (i % j = 0) b = false;break;if (!b) continue;System.out.println(i);break;20假设某员工今年的年薪是30000元,年薪的年增长率6%。编写一个Java应用程序计算该员工10年后的年薪,并统计未来10年(从今年算起)总收入。double nianxin=30000;long sum = 0;for(int i=1;ib?a:b; System.out.println(+m);求三数中的最大数:int a = Integer.parseInt(args2);int b = Integer.parseInt(args3);int c = Integer.parseInt(args4);int t=ab?a:b;int k=tc?t:c;System.out.println(+k);2输入年月日,判断这是这一年中的第几天import java.util.*;public class Answer public static void main(String args) int year, month, day; int days = 0; int d = 0; int e; input fymd = new input(); do e = 0; System.out.print(输入年:); year =fymd.input(); System.out.print(输入月:); month = fymd.input(); System.out.print(输入天:); day = fymd.input(); if (year 0 | month 12 | day 31) System.out.println(输入错误,请重新输入!); e=1 ; while( e=1); for (int i=1; i month; i+) switch (i) case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 4: case 6: case 9: case 11: days = 30; break; case 2: if (year % 400 = 0) | (year % 4 = 0 & year % 100 != 0) days = 29; else days = 28; break; d += days; System.out.println(year + - + month + - + day + 是这年的第 + (d+day) + 天。);class inputpublic int input() int value = 0; Scanner s = new Scanner(System.in); value = s.nextInt(); return value;3 由命令行输入一个4位整数,求将该数反转以后的数,如原数为1234,反转后的数位4321int a, b, c, d, s;int n = Integer.parseInt(args0);a = n / 1000;b = n / 100 % 10;c = n / 10 % 10;d = n % 10;s = d * 1000 + c * 100 + b * 10 + a;System.out.println(反转后数为: + s);4将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。 int b1, b2, b3; for(int m=101; m1000; m+) b3 = m / 100; b2 = m % 100 / 10; b1 = m % 10; if(b3*b3*b3 + b2*b2*b2 + b1*b1*b1) = m) System.out.println(m+是一个水仙花数); 5打印出所有的水仙花数,所谓水仙花数是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个水仙花数,因为153=1的三次方5的三次方3的三次方。int i,j,k,n;for(n=100;n1000;n+) i=n/100;j=n/10%10;k=n%10;if(n=i*i*i+j*j*j+k*k*k)System.out.print(n+ );6判断101-200之间有多少个素数,并输出所有素数。所谓素数n是指,除1和n之外,不能被2(n-1)之间的任何整数整除。public class Answer public static void main(String args) int count = 0; for(int i=101; i200; i+=2) boolean b = false; for(int j=2; j=Math.sqrt(i); j+) if(i % j = 0) b = false; break; else b = true; if(b = true) count +;System.out.println(i ); System.out.println( 素数个数是: + count);7求s=a+aa+aaa+aaaa+aa.a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加由键盘控制。import java.util.Scanner;public class Answer public static void main(String args) long a , b = 0, sum = 0; Scanner s = new Scanner(System.in); System.out.print(输入数字a的值: ); a = s.nextInt(); System.out.print(输入相加的项数:); int n = s.nextInt(); int i = 0; while(i n) b = b + a; sum = sum + b; a = a * 10; + i; System.out.println(sum);8一个数如果恰好等于它的因子之和,这个数就称为完数。例如6=123.编程 找出1000以内的所有完数。public class Answer public static void main(String args) System.out.println(1到1000的完数有: ); for(int i=1; i1000; i+) int t = 0; for(int j=1; j= i/2; j+) if(i % j = 0) t = t + j; if(t = i) System.out.print(i + ); 9打印出如下图案(菱形) * * * *public class Answer public static void main(String args) int H = 7, W = 7;/高和宽必须是相等的奇数 for(int i=0; i(H+1) / 2; i+) for(int j=0; jW/2-i; j+) System.out.print( ); for(int k=1; k(i+1)*2; k+) System.out.print(*); System.out.println(); for(int i=1; i=H/2; i+) for(int j=1; j=i; j+) System.out.print( ); for(int k=1; k=W-2*i; k+) System.out.print(*); System.out.println(); 10在控制台输出以下图形11打印以下图形123456789101112131415 int j = 1,k = 1;/控制换行 for (int i = 1;i k) j = 1; k +; System.out.println(); 12李先生岁数的平方与他的夫人的岁数之和是1053,而他的夫人的岁数的平方与他的岁数之和是873,请编写程序计算李先生及其夫人的岁数各是多少。 for(int i=1;i100;i+) for(int j=i;j100;j+) if(j*j+i=1053&j+i*i=873) System.out.println(丈夫: + j + 岁,妻子: + i +岁。); 13有两个正整数a和b,已知a*b=2048,求a、b各为何值时,a+b的值最小值。int a = 0, b = 0, min =100000, num_a = 0, num_b = 0;for (a = 1; a a + b) min = a + b;num_a = a;num_b = b;System.out.print(num_a + t + num_b);14用1、2、3、4能组成多少无重复数字的三位数int count=0;for(int i=1;i=4;i+)for(int j=1;j=4;j+)for(int k=1;k=4;k+)if(i!=j&i!=k&j!=k)System.out.print(i*100+j*10+k+t);count+;if(count%4=0)System.out.println();System.out.println();System.out.println(可以组成+count+个不同的三位数);15一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第5次落地时,共经过多少米?再反弹弹起多少米?public class Answer public static void main(String args) double h = 100,s = 100; for(int i=1; i10; i+) s = s + h; h = h / 2; System.out.println(经过路程: + s); System.out.println(反弹高度: + h / 2);16输入两个正整数m和n,求其最大公约数和最小公倍数public class Answer public static void main(String args) int a ,b,m;Scanner s = new Scanner(System.in);System.out.print( 键入一个整数: ); a = s.nextInt();System.out.print( 再键入一个整数: ); b = s.nextInt(); deff cd = new deff(); m = cd.deff(a,b)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年西电集团医院招聘(57人)考前自测高频考点模拟试题完整参考答案详解
- 2025广东广州工程技术职业学院第一批招聘一般岗位7人模拟试卷(含答案详解)
- 2025内蒙古通辽市招募企业储备人才37人模拟试卷带答案详解
- 2025年上海奉贤区教育系统事业单位编外用工招聘143名模拟试卷附答案详解(突破训练)
- 2025年灯具配附件:触点项目合作计划书
- 小学安全员培训课件
- 小学安全全员培训方案课件
- 小学安全专题培训心得课件
- Human-VEGFC-mRNA-生命科学试剂-MCE
- HIV-1-protease-IN-15-生命科学试剂-MCE
- 叉车安全技术比武竞赛试题(含答案)
- SMS安全管理体系培训课件
- 民宿改造装修协议合同书
- 国企办公室笔试考试题库及答案
- 电子商务运营推广数据化分析模板
- 2025年探伤工(二级)涡流检测法规试题
- 叉车证培训知识课件
- 北京外汇交易知识培训课件
- 事业单位行测题目及答案
- 喷漆技师基础知识培训课件
- 2025法考客观题库及答案
评论
0/150
提交评论