zoukankan      html  css  js  c++  java
  • 第二次上机作业

    1.编写程序,输入变量x的值,如果是1,输出x=1,如果是5,输出x=5,如果是10,输出x=10,除了以上几个值,都输出x=none。(知识点:if条件语句)

    package Tsst;
    
    import java.util.*;
    
    public class Bss {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("输入x的值");
            int x = sc.nextInt();
            if (x == 1 || x == 5 || x == 10) {
    
                System.out.println("x=" + x);
    
            } else {
    
                System.out.println("x=none");
            }
        }
    }

     2.switch结构实现第1题

    package Tsst;
    
    import java.util.*;
    
    public class Bss {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入x的值");
            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");
                break;
            }
        }
    }

     3。判断一个数字是否能被5和6同时整除(打印能被5和6整除),或只能被5整除(打印能被5整 除),或只能被6整除,(打印能被6整除),不能被5或6整除,(打印不能被5或6整除)

    package Tsst;
    
    import java.util.*;
    
    public class Bss {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("输入数的值");
            int x = sc.nextInt();
            if (x % 5 == 0) {
                System.out.println(x + "只能被5整除");
            } else if (x % 6 == 0) {
                System.out.println(x + "只能被6整除");
            } else if (x % 5 == 0 && x % 6 == 0) {
                System.out.println(x + "只被5和6整除");
            } else {
                System.out.println(x + "不能被5或6整除");
            }
        }
    }

     4.输入一个0~100的分数,如果不是0~100之间,打印分数无效,根据分数等级打印 A(90-100),B(80-89),C,D,E(知识点:条件语句if elseif)

    package Tsst;
    
    import java.util.*;
    
    public class Bss {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个0-100之间的数");
            int x = sc.nextInt();
            if (x / 10 >= 9 && x / 10 <= 10) {
                System.out.println("A");
            } else if (x / 10 >= 8 & x / 10 < 9) {
                System.out.println("B");
            } else if (x / 10 >= 7 & x / 10 < 8) {
                System.out.println("C");
            } else if (x / 10 >= 6 & x / 10 < 7) {
                System.out.println("D");
            } else if (x / 10 < 6) {
                System.out.println("E");
            } else if (x < 0 || x > 100) {
                System.out.println("打印的分数无效");
            }
        }
    }

     5.输入三个整数x,y,z,请把这三个数由小到大输出(知识点:条件语句)

    package Tsst;
    
    import java.util.*;
    
    public class Bss {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入x,y,z三个整数");
            int x = sc.nextInt();
            int y = sc.nextInt();
            int z = sc.nextInt();
    
            if (x < y) {
                int a = x;
                x = y;
                y = a;
            }
            if (x < z) {
                int a = x;
                x = z;
                z = a;
            }
            if (y < z) {
                int a = y;
                y = z;
                z = a;
            }
            System.out.println(z + " " + y + " " + x);
        }
    }

  • 相关阅读:
    mybatis自动生成代码配置文件
    Struts2的类型转换器
    CSS布局自适应高度终极方法
    Winform WebBrowser控件对访问页面执行、改写、添加Javascript代码
    利用using语句解决Lock抛出异常时发生死锁的问题
    Flash与Silverlight终极大比拼
    System.Collections.Specialized.NameValueCollection PostVars
    Hook浏览器控件WebBrowser对WININET.dll的调用
    WebBrowser中打开新页面保留sessionid
    Linksys路由器自动重启加流量
  • 原文地址:https://www.cnblogs.com/qsf1975747------/p/12573560.html
Copyright © 2011-2022 走看看