码迷,mamicode.com
首页 > 编程语言 > 详细

Java学习笔记10

时间:2016-12-22 22:57:49      阅读:484      评论:0      收藏:0      [点我收藏+]

标签:布尔   bsp   oid   port   switch   welcome   and   ext   tee   

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));
    }
}

 

Java学习笔记10

标签:布尔   bsp   oid   port   switch   welcome   and   ext   tee   

原文地址:http://www.cnblogs.com/datapool/p/6213013.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!