Question: I am new to LINUX. This question sounds simple and stupid, but I suppose this has a lot of meaning behind it. "HOW COMMANDS ARE PROCESSED IN LINUX?". Which means suppose if I give ls command,what makes it to display list of all files inside the directory?. I have been searching for the answer, and I could not find any clear explanation for the same. Please help me to solve the same.

Answer: 
The simplest option would probably be to use `String.replaceAll`:

```
text = text.replaceAll("[0.]*$", "");

```

The `$` makes sure it's only trimming the end of the string.

Note that if you start with "0" you'll end up with an empty string - think about what you want the result to be in that situation.
OK, expanding on Jon's answer, and assuming that you don't want to count the decimal point, then the following code should cope with both integers and decimal numbers in your string:

```
// Start by taking note of the original string length
int startLength = text.length();
// Remove any trailing zeroes
text = text.replaceAll("0*$", "");
// Remove any zeroes immediately to the left of any trailing decimal point
text = text.replaceAll("0*.$", ".");
// Find the number of zeroes by subtracting the lengths
int numZeroes = startLength - text.length();

```

or if you want it in a single statement:

```
int numZeroes = text.length() - text.replaceAll("0*$", "").replaceAll("0*.$", ".").length();

```

Which looks horrible, but has the advantage of not altering the original string.