第四次作业
package com.xuexiao; import java.util.Scanner; public class Text3 { public static void main(String[] args) { // TODO Auto-generated method stub //1.输入变量x,如果1 输出1 如果5 输出5 如果10 输出10 除了以上几个 都输出x=none. Scanner sc = new Scanner(System.in); System.out.print("请输入一个数:"); int x = sc.nextInt(); if(x == 1 ) { System.out.println("x=1"); } else if(x == 5) { System.out.println("x=5"); } else if(x == 10) { System.out.println("x=10"); } else { System.out.println("x=none"); } } }
package com.xuexiao; import java.util.Scanner; public class Text3 { public static void main(String[] args) { // TODO Auto-generated method stub //2.switch实现1 Scanner sc = new Scanner(System.in); System.out.print("请输入一个数:"); int x = sc.nextInt(); 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("x=none"); } } }
package com.xuexiao; import java.util.Scanner; public class Text3 { public static void main(String[] args) { /*3.判断一个数字是否能被5和6同时整除(打印能被5和6整除), * 或只能被5整除(打印能被5整 除),或只能被6整除,(打印能被6整除) * ,不能被5或6整除,(打印不能被5或6整除)*/ Scanner sc = new Scanner(System.in); System.out.print("请输入一个数:"); int x = sc.nextInt(); if(x % 5 == 0 && x % 6 == 0) { System.out.println("能被5和6整除"); }else if(x % 5 == 0) { System.out.println("能被5整除"); }else if(x % 6 == 0) { System.out.println("能被6整除"); }else { System.out.println("不能被5和6整除"); } } }
package com.xuexiao; import java.util.Scanner; public class Text3 { public static void main(String[] args) { /*4.输入一个0~100的分数,如果不是0~100之间,打印分数无效, * 根据分数等级打印 A(90-100),B(80-89),C,D,E(知识点:条件语句if elseif)*/ Scanner sc = new Scanner(System.in); System.out.print("请输入一个数:"); int x = sc.nextInt(); if(0 <= x && x<=100 ) { if (x >=90 && x<=100) { System.out.println("等级为A"); }else if (x >=80 && x<=89) { System.out.println("等级为B"); }else if (x >=70 && x<=79) { System.out.println("等级为C"); }else if (x >=60 && x<=69) { System.out.println("等级为D"); }else if (x >=50 && x<=59) { System.out.println("等级为E"); }else if( x < 49) { System.out.println("太差了"); }else { System.out.println("输入无效"); } } } }
package com.xuexiao; import java.util.Scanner; public class Text3 { public static void main(String[] args) { /*5.输入三个整数x,y,z,请把这三个数由小到大输出(知识点:条件语句)*/ Scanner sc = new Scanner(System.in); System.out.print("请输入第1个数:"); int x = sc.nextInt(); System.out.print("请输入第2个数:"); int y = sc.nextInt(); System.out.print("请输入第3个数:"); int z = sc.nextInt(); int sum = x+y+z; int max = ((x>y)?(x>z?x:z):(y>z?y:z)); int min = ((x<y)?(x<z?x:z):(y<z?y:z)); int mid = sum - max - min; System.out.println("从小到大为:"+min+" "+mid+" "+max); } }