We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
How do I get the nextInt() function to give me the leading zero? My code works when I manually give it the input from test case 3 it gives me the right thing, but with the scanner it reads 987654321 instead of 0987654321.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticString[]getDigits(intn){// number has less than 10 digitsStringnum=Integer.toString(n);String[]digitArray=num.split("");returndigitArray;}publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);intn=in.nextInt();String[]digits=getDigits(n);for(Strings:digits){System.out.print((Integer.parseInt(s)+1)%10);}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Security - Message Space and Ciphertext Space
You are viewing a single comment's thread. Return to all comments →
How do I get the
nextInt()
function to give me the leading zero? My code works when I manually give it the input from test case 3 it gives me the right thing, but with the scanner it reads 987654321 instead of 0987654321.