• 第二次练习作业


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

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

    2.用switch结构实现第1题

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

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

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

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

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

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

     1 package as;
     2 import java.util.Scanner;
     3 public class unll {
     4     public static void main(String[] args) {
     5         // TODO Auto-generated method stub
     6         Scanner sc= new Scanner(System.in);
     7         System.out.println("请输入x的值");
     8         int x=sc.nextInt();
     9         System.out.println("请输入y的值");
    10         int y=sc.nextInt();
    11         System.out.println("请输入z的值");
    12         int z=sc.nextInt();
    13         if(x>y){
    14             if(z>x){
    15                 System.out.println(y+","+x+","+z);
    16             }else if(y>z){
    17                 System.out.println(z+","+y+","+x);
    18             }else{
    19                 System.out.println(y+","+z+","+x);
    20             }
    21         }else{
    22             if(x>z){
    23                 System.out.println(z+","+x+","+y);
    24             }else if(z>y){
    25                 System.out.println(x+","+y+","+z);
    26             }else{
    27                 System.out.println(x+","+z+","+y);
    28             }
    29         }
    30     }
    31 }
  • 相关阅读:
    yii2框架(一)安装
    修改hosts搭建本地站点
    php版本管理工具composer安装及使用
    nodejs学习笔记Node.js 调试命令
    angular自定义指令命名的那个坑
    MongoDB Windows环境安装及配置( 一)
    JavaSE 面试题: 类初始化和实例初始化等
    JavaSE 面试题: 成员变量与局部变量
    JavaSE 面试题: 方法的参数传递机制
    JavaSE 笔试题: 自增变量
  • 原文地址:https://www.cnblogs.com/zxp-0101/p/12573568.html
Copyright © 2020-2023  润新知