File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .NavigableMap ;
2
+ import java .util .TreeMap ;
3
+ public class NavigableMap7 {
4
+ // floorKey
5
+ public static void main (String [] args ) throws Exception {
6
+ NavigableMap <Float , Integer > map = new TreeMap <>();
7
+ map .put (1.8f ,11 );
8
+ map .put (2.6f , 9 );
9
+ map .put (3.4f , 78 );
10
+ map .put (4.3f , 5 );
11
+ map .put (5.6f , 1 );
12
+ map .put (6.8f , 3 );
13
+ System .out .println ("Map:" + map );
14
+ System .out .println ("Floor Key:" + map .floorKey (3.0f )); // less than 3.4f and greater than 2.6f,hence returns 2.6f (floor Value)
15
+ System .out .println ("Floor Key:" + map .floorKey (1.0f )); //less than 1.8fi.e(First Entry) ,hence no floor value , returns null.
16
+ System .out .println ("Floor Key:" + map .floorKey (1.9f )); //less than 2.6f and greater than 1.8f,hence returns 1.8f (floor Value)
17
+ System .out .println ("Floor Key:" + map .floorKey (3.4f )); //equal to 3.4f ,hence returns 3.4f (If equal , it becomes Floor Value of itself)
18
+ System .out .println ("Floor Key:" + map .floorKey (3.5f )); //less than 4.3f and greater than 3.4f,hence returns 3.4f (floor Value)
19
+ System .out .println ("Floor Key:" + map .floorKey (6.5f )); //less than 6.8f and greater than 5.6f,hence returns 5.6f (floor Value)
20
+ System .out .println ("Floor Key:" + map .floorKey (6.8f )); //equal to 6.8f ,hence returns 6.8f (If equal , it becomes Floor Value of itself)
21
+ System .out .println ("Floor Key:" + map .floorKey (7.0f )); //greater than 6.8f , returns 6.8f(Floor Value).
22
+
23
+ }
24
+
25
+ }
You can’t perform that action at this time.
0 commit comments