this is my code
System.out.println("Enter any integer number ");
int number = scan.nextInt();
while (number > 0) { System.out.print( number % 10 + ",");number = number / 10;}
To clarify if the user enter 1234 the output should be 4,3,2,1,
how can i edit the code to remove the comma after the last num? something like 4,3,2,1
Since everyone is having a field day, here's mine:
while (number > 0) {
System.out.print( number % 10 + ((number/=10)>0 ? "," : ""));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With