Solution:
if(inputString.compareTo("0") == 0)
return;
break;
I know you are in the process of learning. Let me explain why the following is the worst way of writing java
BAD CODE
while ( i > 0) {
reverseString = reverseString + inputString.charAt(i);
i--;
}
Why?
By default java concat string using
StringBuilder class(Except some literal value cases). so, if you write
String x = a + b;
Java will process this as
StringBuilder temp_var = new StringBuilder();
temp_var.add(a);
temp_var.add(b);
x = temp_var.toString();
This look clean on a string that is written outside of a loop. But what would happen when you use this inside a loop? It will create object for every operation.