2017-12-19作业 if和switch的使用
来源:互联网 发布:反美颜软件有可能 编辑:程序博客网 时间:2024/06/06 03:46
时间有多改成了方法,可以正常运行。
导入栏:
package day1219;import java.util.Scanner;public class entry {public static void main(String[] args){System.out.print("请输入你要查看的作业:");Scanner a = new Scanner(System.in);String a1 = a.next();//System.out.print(a1);for(int i = 0;i<25;i++){System.out.print(" * ");}System.out.println();if(a1.equals("homework1")){homework1 s = new homework1();s.run();}else if(a1.equals("homework2")){homework2 s = new homework2();s.run(); }else if(a1.equals("homework3")){ homework3 s = new homework3();s.run(); }else if(a1.equals("homework4")){ homework4 s = new homework4();s.run(); }else{ System.out.println("您输入的作业不存在!"); System.out.println("没有找到此作业!"); }}}
homework1:
/** * 2:输入赵本山的考试成绩,显示所获奖励成绩==100分,爸爸给他买辆车成绩>=90分,妈妈给他买MP490分>成绩>=60分,妈妈给他买本参考书成绩<60分,什么都不买 */package day1219;import java.util.Scanner;public class homework1 {public static void run(){System.out.print("输入赵本山的考试成绩,显示所获奖励:");Scanner a = new Scanner(System.in);int sroce = a.nextInt();if(sroce>100||sroce<0){System.out.println("输入有误");}else if(sroce == 100){System.out.println("阿爸给你买辆车");}else if(sroce>=90&&sroce<100){System.out.println("阿妈给你买MP4");}else if(sroce>=60&&sroce<90){System.out.println("阿妈给你买本参考书");}else{System.out.println("什么都不买");}}}
homework2:
/** * 3:由控制台输入两个整数,获取两个数据中较大的值 */package day1219;import java.util.Scanner;public class homework2 {public static void run(){Scanner a = new Scanner(System.in);System.out.print("请输入第一个数:");int a1 = a.nextInt();System.out.print("请输入第二个数:");int a2 = a.nextInt();if(a1>a2){System.out.println("第一个数的值较大,第一个数的值为:" + a1);}else if(a1<a2){System.out.println("第二个数的值较大,第二个数的值为:" + a2);}else{System.out.println("两个数的值一样大,两个数的值为:" + a1);}}}
homework3:
/** * 4:由控制台输入一个整数,判断该整数是奇书还是偶数 */package day1219;import java.util.Scanner;public class homework3 {public static void run(){Scanner a = new Scanner(System.in);System.out.print("请输入一个整数:");int a1 = a.nextInt();if(a1%2==0){System.out.println("这个数是一个偶数!");}else{System.out.println("这个数是一个奇数!");}}}
homework4:
/** * 输入3个数并从小到大排序 */package day1219;import java.util.Scanner;public class homework4 {public static void run(){Scanner a = new Scanner(System.in);System.out.print("请输入第一个数:");int a1 = a.nextInt();System.out.print("请输入第二个数:");int a2 = a.nextInt();System.out.print("请输入第三个数:");int a3 = a.nextInt();//傻瓜方法//if(a1>=a2&&a2>=a3){//System.out.println(a1+","+a2+","+a3);//}else if(a1>=a3&&a3>=a2){//System.out.println(a1+","+a3+","+a2);//}else if(a1<=a2&&a2<=a3){//System.out.println(a3+","+a2+","+a1);//}else if(a2<=a1&&a3>=a1){//System.out.println(a3+","+a1+","+a2);//}else if(a1<=a2&&a3<=a1){//System.out.println(a2+","+a1+","+a3);//}else if(a1<=a3&&a2>=a3){//System.out.println(a2+","+a3+","+a1);//}//选择排序int[] arr = {a1,a2,a3};for(int x = 0;x<arr.length-1;x++){for(int y = x+1;y<arr.length;y++){if(arr[x]>arr[y]){int temp = arr[x];arr[x] = arr[y];arr[y] = temp;}}}for(int x = 0;x<arr.length;x++){System.out.print(arr[x]+",");}}}
阅读全文
0 0
- 2017-12-19作业 if和switch的使用
- if和switch的应用
- if和switch的区别
- IF和SWITCH的原理
- if和switch的区别
- 选择结构的程序设计——if和switch使用
- js---javaScript (if....else和switch...case的使用实例)
- 使用if和Switch判断学生成绩
- [Java] 使用多个 if 语句、else if 和 switch 的区别
- 选择 | 循环 | 语句(if,if……else,switch,while,for)的理解和使用
- if 和 switch的区别和应用
- 如何区别 if switch语句的使用?
- if语句与switch的使用
- if与switch的使用与区别
- Java(if-switch的使用)
- if-else和switch的效率问题
- if else 和 switch的效率
- if else 和switch 的区别
- Webpack3的使用(五)
- mysql数据库授权操作
- 篇外篇【今天参加了一个区块链项目的私募,说说内心的感觉】
- bing搜索
- 简单了解阿里云批量计算(上篇)
- 2017-12-19作业 if和switch的使用
- jQuery.ajax() 函数详解,很全很好
- Java并发编程实战-章二~volatile的思考
- SpannableString 富文本编辑
- HTTPSessionListner的用法
- Mac 终端命令记录
- LUA 排序算法和性能分析[1]:table.sort
- KAFKA 1.0 文档(六):消费者配置
- 基本模块--fs