Unwanted output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Unwanted output

Hi, I had written a program which takes any year from user between 1- 3000 and print its century. Ex Input: 2045 Output: 21st Century But when I input 1000 it print: 11st century Here 11 is right but why 'st' is showing I had written in if statment than if it 11 than show 'th' Please help me https://code.sololearn.com/c7ovQ48ToX2e/?ref=app https://code.sololearn.com/c7ovQ48ToX2e/?ref=app

27th Oct 2019, 10:24 AM
Nitin Tiwari
Nitin Tiwari - avatar
1 Answer
+ 2
its because you're passing 10 to post where you're getting the character 0 from 10 (charAt(1)) and incrementing it by 1 which results in 1, and your condition for 1 is to return st
27th Oct 2019, 12:15 PM
George Samanlian