Java学习笔记10
Posted xiaorong1115
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)); } }
以上是关于Java学习笔记10的主要内容,如果未能解决你的问题,请参考以下文章