From e05426d3a5c0b2df6ccaf44bd2fb48d3f04975fd Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Sat, 25 Jul 2026 10:16:05 +0800 Subject: [PATCH] =?UTF-8?q?day08-Math=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day08/src/com/inmind/math04/Test16.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 day08/src/com/inmind/math04/Test16.java diff --git a/day08/src/com/inmind/math04/Test16.java b/day08/src/com/inmind/math04/Test16.java new file mode 100644 index 0000000..1f6d1b5 --- /dev/null +++ b/day08/src/com/inmind/math04/Test16.java @@ -0,0 +1,24 @@ +package com.inmind.math04; +/* +计算在 -10.8 到5.9 之间,绝对值大于6 或者小于2.1 的整数有多少个? +分析: +取值范围: -10.8 ~5.9 +条件>6||<2.1 +定义一个变量来计数 + */ +public class Test16 { + public static void main(String[] args) { + int count = 0;//定义变量来计数 + double start = -10.8; + double end = 5.9; + //取值范围: -10.8 ~5.9 + for (double i = Math.ceil(start); i < end; i++) { + //条件>6||<2.1 + if ((Math.abs(i) > 6) || (Math.abs(i) < 2.1)) { + System.out.println(i); + count++; + } + } + System.out.println(count); + } +}