> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/java/java-basics/java-data-types/specialized-classes/bigdecimal/examples.md).

# Examples

## Example 1

Given an array, **arr**, of **n** real number strings. Task is to sort them in descending order. Note that each number must be printed in the exact same format as it is given in input, meaning that .1 is printed as .1, and 0.1 is printed as 0.1. If two numbers represent numerically equivalent values (e.g. .1 is equivalent to 0.1), then they must be listed in the same order as they were received in the input).

{% hint style="info" %}
1 <= n <= 300

Each element of **arr** has atmost 250 digits.

```
 Sample Input
 9
 -101
 50
 0
 55.6
 90
 0.13
 .13
 01.34
 000.000

Sample Output
 90
 55.6
 50
 01.34
 0.13
 .13
 0
 000.000
 -101
```

{% endhint %}

```java
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        sc.close();

        System.out.println(Arrays.toString(s));
        Arrays.sort(s, (o1, o2) -> {
            // Convert strings to BigDecimal for comparison
            BigDecimal bd1 = new BigDecimal(o1);
            BigDecimal bd2 = new BigDecimal(o2);
            // Sort in descending order
            return bd2.compareTo(bd1);
        });

        for (int i = 0; i < n; i++) {
            System.out.println(s[i]);
        }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/java/java-basics/java-data-types/specialized-classes/bigdecimal/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
