zoukankan      html  css  js  c++  java
  • Java学习笔记10

    31.
    编写当年龄age大于13且小于18时结果为true的布尔表达式
    age > 13 && age < 18

    32.
    编写当体重weight大于50或身高大于160时结果为true的布尔表达式
    weight > 50 || height > 160

    33.
    编写当体重weight>50且身高height大于160时结果为true的布尔表达式
    weight > 50 && height > 160

    34.
    编写当体重weight大于50或身高height大于160,但不能同时满足这两个条件时,结果为true的布尔表达式
    weight > 50 ^ height > 160

    switch语句支持byte,short,char,int,enum,String,不支持long数据类型

    package welcome;
    
    import java.util.Scanner;
    
    /*
     * 解一元二次方程
     */
    
    public class ComputeEquation {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            
            System.out.print("Enter a, b, c: ");
            double a = in.nextDouble();
            double b = in.nextDouble();
            double c = in.nextDouble();
            
            double judgeExpression = b * b - 4 * a * c;
            
            double r1 = 0;
            double r2 = 0;
            if(judgeExpression > 0){
                r1 = (-b + Math.pow(judgeExpression, 0.5)) / (2 * a);
                r2 = (-b - Math.pow(judgeExpression, 0.5)) / (2 * a);
                System.out.println("The roots are " + r1 + " and " + r2);
            }else if(judgeExpression == 0){
                r1 = (-b + Math.pow(judgeExpression, 0.5)) / (2 * a);
                System.out.println("The root is " + r1);
            }else{
                System.out.println("The equation has no real roots.");
            }
        }
    }
    package welcome;
    
    import java.util.Scanner;
    /*
     * 检查一个数字是否是偶数
     */
    public class CheckEven {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            
            System.out.print("Enter an integer: ");
            int number = in.nextInt();
            
            System.out.printf("Is %d an even number? %b ", number, (number % 2 == 0));
        }
    }
  • 相关阅读:
    tensorflow 镜像
    TDD、BDD、DDD
    Node.js结合Selenium做Web自动化测试
    Selenium 对元素element的操作举例
    Selenium UI 举例 getCssValue
    《测之重器——自动化测试框架搭建指南》
    《Robot Framework自动化测试修炼宝典》道长
    SQLServer中round函数
    SQLServer中对时间和长度的处理
    SQLServer中获取所有数据库名、所有表名、所有字段名的SQL语句
  • 原文地址:https://www.cnblogs.com/datapool/p/6213013.html
Copyright © 2011-2022 走看看