Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class Order {
    public static void main(String[] args) {
        NavigableSet<Integer> number = new TreeSet<Integer>();
        number.add(0);    number.add(10);
        number.add(6);    number.add(15);
        number.add(-4);    number.add(10);
        number.add(8);    number.add(16);
        number.add(594);    number.add(154);
        number.add(+2);
        Iterator num = number.descendingIterator();
        String result = "";
        while (num.hasNext()) {
            result += num.next() + ", ";
        }
        System.out.println(extracted(result));
    }
    private static String extracted(String result) {
        return result.substring(0, result.length() - 2);
    }
}


594, 154, 16, 15, 10, 8, 6, 2, 0, -4
594, 154, 16, 15, 10, 8, 6, 2, 0, -
-4, 0, 2, 6, 8, 10, 15, 16, 154, 594
-4, 0, 2, 6, 8, 10, 15, 16, 154, 59
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Iterator

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App