zoukankan      html  css  js  c++  java
  • 第二次上机练习

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

    package xx;
    
    import java.util.Scanner;
    
    public class pika {
    
        public static void main(String[] args) {
            Scanner in =new Scanner(System.in);
            int a = in.nextInt();
            if(a==1 || a==5 || a==10) {
                System.out.println("x="+a);
            }else {
             System.out.println("x=none");
            
            }
        }
    }

    2.用switch结构实现第1题

    package xx;
    
    import java.util.Scanner;
    
    public class pika {
    
        public static void main(String[] args) {
            Scanner in =new Scanner(System.in);
            int a = in.nextInt();
            switch(a) {
            case 1:
            case 5:
            case 10:
                System.out.println("x="+a);
                break;
                default:System.out.println("x=none");
            }
        }
    
    }

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

    package xx;
    
    import java.util.Scanner;
    
    public class pika {
    
        public static void main(String[] args) {
            Scanner s = new Scanner (System.in);
            System.out.print ("请输入一个数: ");
            int i = s.nextInt();
            if (i%5==0 && i%6==0) {
                System. out.println (i+"能同时被5和6整除");
            }
                else if(i%5==0) {
                System. out.println(i+"能只被5整除");
                }
                else if (i%6==0) {
                System. out.println(i+"能只被6整除");
                }
                else {
                System. out.println(i+"不能被5和6整除");
            }
        }
    
    }

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

    package xx;
    
    import java.util.Scanner;
    
    public class pika {
    
        public static void main(String[] args) {
            Scanner sc= new Scanner(System.in);
            System.out.println("请输入分数的值");
            int x=sc.nextInt();
            if(x<0 || x>100) {
                System.out.println("打印分数无效");
            }else 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");
            }
        }
    
    }

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

    package xx;
    
    import java.util.Scanner;
    
    public class pika {
    
        public static void main(String[] args) {
            Scanner sc= new Scanner(System.in);
            System.out.println("请输入x的值");
            int x=sc.nextInt();
            System.out.println("请输入y的值");
            int y=sc.nextInt();
            System.out.println("请输入z的值");
            int z=sc.nextInt();
            if(x>y && y>z) {
                System.out.println("输出"+z+","+y+","+x);
            }else if(x>z && z>y) {
                System.out.println("输出"+y+","+z+","+x);
            }else if(y>x && x>z) {
                System.out.println("输出"+z+","+x+","+y);
            }else if(y>z && z>x) {
                System.out.println("输出"+x+","+z+","+y);
            }else if(z>y && y>x) {
                System.out.println("输出"+x+","+y+","+z);
            }else if(z>x && x>y) {
                System.out.println("输出"+y+","+x+","+z);
            }
        }
    
    }

  • 相关阅读:
    hdu 1199 Color the Ball 离散线段树
    poj 2623 Sequence Median 堆的灵活运用
    hdu 2251 Dungeon Master bfs
    HDU 1166 敌兵布阵 线段树
    UVALive 4426 Blast the Enemy! 计算几何求重心
    UVALive 4425 Another Brick in the Wall 暴力
    UVALive 4423 String LD 暴力
    UVALive 4872 Underground Cables 最小生成树
    UVALive 4870 Roller Coaster 01背包
    UVALive 4869 Profits DP
  • 原文地址:https://www.cnblogs.com/x20425535/p/12573164.html
Copyright © 2011-2022 走看看