0

Why my code is giving wrong output for 6900 it is showing 'Six Nine' but it should show ' Six Nine Zero Zero'.

Please help https://code.sololearn.com/cgFB4oIY7Y4C/?ref=app

1st Nov 2023, 2:32 PM
Ravi Chauhan
Ravi Chauhan - avatar
3 Réponses
+ 4
Because s = 96 after first while loop.
1st Nov 2023, 3:52 PM
A͢J
A͢J - avatar
+ 2
Hi Ravi Chauhan If I understand it right you reverse the number. 123 -> s = 321 1037 -> s = 7301 But now check s when you enter a number with a 0 at the end: 120 -> s = 12 6900 -> s = 96 Because s is an Integer and Integers don't start with 0's. So you lose them. Maybe it helps when you use String for s. But I guess it is easier to use an ArrayList to store each digit. Then you can loop through the list from the end.
1st Nov 2023, 4:09 PM
Denise Roßberg
Denise Roßberg - avatar
2nd Nov 2023, 4:55 AM
Bob_Li
Bob_Li - avatar