Skip to content

Commit 8f77c35

Browse files
committed
Numner methods revise
1 parent 0471f2b commit 8f77c35

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

1.93 KB
Binary file not shown.

src/revise/numericmethods/NumericMethodExamples.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.OptionalDouble;
66
import java.util.OptionalInt;
77
import java.util.OptionalLong;
8+
import java.util.stream.Collectors;
89
import java.util.stream.IntStream;
910
import java.util.stream.LongStream;
1011

@@ -22,6 +23,37 @@ public static void main(String args[]) {
2223
basic5();
2324
System.out.println("*****Basic6****");
2425
basic6();
26+
System.out.println("*****Basic7****");
27+
basic7();
28+
System.out.println("*****Basic8****");
29+
basic8();
30+
System.out.println("*****Basic9****");
31+
basic9();
32+
System.out.println("*****Basic10****");
33+
basic10();
34+
}
35+
36+
public static void basic10() {
37+
Double sumValue = IntStream.rangeClosed(1, 10).mapToDouble(Double::new).sum();
38+
System.out.println("Double value is : " + sumValue);
39+
}
40+
41+
public static void basic8() {
42+
List<Integer> values = IntStream.rangeClosed(1, 10).mapToObj(Integer::new).collect(Collectors.toList());
43+
values.forEach(System.out::println);
44+
}
45+
46+
public static void basic9() {
47+
Long sumValue = IntStream.rangeClosed(1, 10).mapToLong(Long::new).sum();
48+
System.out.println("Long value is : " + sumValue);
49+
}
50+
51+
public static void basic7() {
52+
List<Integer> values = IntStream.rangeClosed(1, 100).boxed().collect(Collectors.toList());
53+
values.forEach(System.out::println);
54+
55+
int sumValue = values.stream().mapToInt(Integer::intValue).sum();
56+
System.out.println(sumValue);
2557

2658
}
2759

0 commit comments

Comments
 (0)