• 第二次上机练习


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

     1 package text;
     2 import java.util.Scanner;
     3 public class ZuoYe {
     4 
     5     public static void main(String[] args) {
     6         // TODO Auto-generated method stub
     7        Scanner input = new Scanner(System.in);
     8        System.out.println("输入x的值:");
     9         int x = input.nextInt();
    10             if (x==1){
    11                 System.out.println("x=1");
    12      }else if(x==5){
    13                 System.out.println("x=5");
    14      }else if (x==10){
    15                 System.out.println("x=10");
    16      } else {
    17                 System.out.println("x=none");
    18         }
    19 
    20     }
    21 
    22 }

    2.用switch结构实现第1题

     1 package text;
     2 import java.util.Scanner;
     3 public class ZuoYe {
     4 
     5     public static void main(String[] args) {
     6         // TODO Auto-generated method stub
     7        Scanner input = new Scanner(System.in);
     8        System.out.println("输入x的值:");
     9         int x = input.nextInt();
    10         switch(x){
    11             case 1:
    12                 System.out.println("x=1");
    13                 break;
    14             case 5:
    15                 System.out.println("x=5");
    16                 break;
    17             case 10:
    18                 System.out.println("x=10");
    19                 break;
    20             default:
    21                 System.out.println("x=none");
    22                 break;
    23         }
    24 
    25     }
    26 
    27 }

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

     1 package text;
     2 import java.util.Scanner;
     3 public class ZuoYe {
     4 
     5     public static void main(String[] args) {
     6         // TODO Auto-generated method stub
     7        Scanner input = new Scanner(System.in);
     8        System.out.println("输入x的值:");
     9         int x = input.nextInt();
    10            if (x%5==0&&x%6==0){
    11                System.out.println("打印能被5和6整除");
    12            }else if(x%5==0&&x%6!=0){
    13                System.out.println("打印能被5整除");
    14            }else if (x%6==0&&x%5!=0){
    15                System.out.println("打印能被6整除");
    16         } else {
    17             System.out.println("打印不能被5和6整除");
    18         }
    19     }
    20 }

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

     1 package text;
     2 import java.util.Scanner;
     3 public class ZuoYe {
     4 
     5     public static void main(String[] args) {
     6         // TODO Auto-generated method stub
     7        Scanner input = new Scanner(System.in);
     8        System.out.println("输入一个1~100的分数:");
     9         int x = input.nextInt();
    10            if (x>=90&&x<=100){
    11                  System.out.println("分数等级打印为A");
    12            }else if(x>=80&&x<=89){
    13                  System.out.println("分数等级打印为B");
    14            }else if(x>=70&&x<=79){
    15                  System.out.println("分数等级打印为C");
    16            }else if(x>=60&&x<=69){
    17                  System.out.println("分数等级打印为D");
    18            }else if(x>=50&&x<=59){
    19                  System.out.println("分数等级打印为E");
    20            }else {
    21                  System.out.println("打印分数无效");
    22         }
    23     }
    24 }

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

     1 package text;
     2 import java.util.Scanner;
     3 public class ZuoYe {
     4 
     5     public static void main(String[] args) {
     6         // TODO Auto-generated method stub
     7        Scanner input = new Scanner(System.in);
     8        System.out.println("输入三个整数x,y,z:");
     9         int x = input.nextInt();
    10         int y = input.nextInt();
    11         int z = input.nextInt();
    12         if(x>y&&y>z){
    13             System.out.println(z+"<"+y+"<"+x);
    14         }else if(x>z&&z>y){
    15             System.out.println(y+"<"+z+"<"+x);
    16         }else if(y>x&&x>z){
    17             System.out.println(z+"<"+x+"<"+y);
    18         }else if(y>z&&z>x){
    19             System.out.println(x+"<"+z+"<"+y);
    20         }else if(z>x&&x>y){
    21             System.out.println(y+"<"+x+"<"+z);
    22         }else if(z>y&&y>x){
    23             System.out.println(x+"<"+y+"<"+z);
    24         }
    25     
    26     }
    27 }

     

  • 相关阅读:
    Seminar Schedule
    数学建模之Python操作csv文件
    Pandas之csv文件对列行的相关操作
    Python之文件读写(csv文件,CSV库,Pandas库)
    PATA1028 List Sorting
    19.8.9(全局变量和局部变量的作用域)
    PATA1012The Best Rank(25分)
    DEV-gridview导出Excel
    WPF文本换行
    下拉框--可多选
  • 原文地址:https://www.cnblogs.com/gwz-1314/p/12573762.html
Copyright © 2020-2023  润新知