Compare commits
2 Commits
f80521d4a5
...
ff273fbcde
Author | SHA1 | Date | |
---|---|---|---|
ff273fbcde | |||
ce86998025 |
15
src/chapter5/Example16.java
Normal file
15
src/chapter5/Example16.java
Normal file
@ -0,0 +1,15 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example16 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("计算绝对值的结果: " + Math.abs(-10));
|
||||
System.out.println("求大于参数的最小整数: " + Math.ceil(5.6));
|
||||
System.out.println("求小于参数的最大整数: " + Math.floor(-4.2));
|
||||
System.out.println("对小数进行四舍五入后的结果: " + Math.round(-4.6));
|
||||
System.out.println("求两个数的较大值: " + Math.max(2.1, -2.1));
|
||||
System.out.println("求两个数的较小值: " + Math.min(2.1, -2.1));
|
||||
System.out.println("生成一个大于等于0.0小于1.0随机值: " + Math.round(10 * Math.random()));
|
||||
System.out.println("开平方的结果: "+Math.sqrt(4));
|
||||
System.out.println("指数函数的值: "+Math.pow(2, 3));
|
||||
}
|
||||
}
|
13
src/chapter5/Example17.java
Normal file
13
src/chapter5/Example17.java
Normal file
@ -0,0 +1,13 @@
|
||||
package chapter5;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Example17 {
|
||||
public static void main(String[] args) {
|
||||
Random r = new Random(); // 不传入种子
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// 随机产生10个[0,100)之间的整数
|
||||
System.out.println(r.nextInt(100));
|
||||
}
|
||||
}
|
||||
}
|
13
src/chapter5/Example18.java
Normal file
13
src/chapter5/Example18.java
Normal file
@ -0,0 +1,13 @@
|
||||
package chapter5;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Example18 {
|
||||
public static void main(String[] args) {
|
||||
Random r = new Random(13);
|
||||
// 随机产生10个[0,100)之间的整数
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(r.nextInt(100));
|
||||
}
|
||||
}
|
||||
}
|
4
src/chapter5/Example20.java
Normal file
4
src/chapter5/Example20.java
Normal file
@ -0,0 +1,4 @@
|
||||
package chapter5;
|
||||
|
||||
public class Example20 {
|
||||
}
|
24
src/chapter5/Example21.java
Normal file
24
src/chapter5/Example21.java
Normal file
@ -0,0 +1,24 @@
|
||||
package chapter5;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class Example21 {
|
||||
public static void main(String[] args) {
|
||||
LocalDate now = LocalDate.now();
|
||||
LocalDate of = LocalDate.of(2015, 12, 12);
|
||||
|
||||
System.out.println("今年是" + now.getYear() + "年");
|
||||
System.out.println("月份:" + now.getMonth());
|
||||
System.out.println("月份:" + now.getMonthValue());
|
||||
System.out.println("日期:" + now.getDayOfMonth());
|
||||
System.out.println("今年中的第几天:" + now.getDayOfYear());
|
||||
System.out.println("周几:" + now.getDayOfWeek());
|
||||
|
||||
System.out.println("====判断相关的方法====");
|
||||
|
||||
System.out.println("of是否在now之前?" + of.isBefore(now));
|
||||
System.out.println("of是否在now之后?" + of.isAfter(now));
|
||||
System.out.println("of和now是否相等?" + of.isEqual(now));
|
||||
System.out.println("of是否闰年?" + of.isLeapYear());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user