首页 > 代码库 > Java学习笔记10
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。