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.
I have this Java code. It passes all the test cases. But I dont think this is a good approach. Any suggestions on how to change it?
publicstaticvoidmain(String[]args){/* * Enter your code here. Read input from STDIN. Print output to STDOUT. * Your class should be named Solution. */Scannersc=newScanner(System.in);Stringstr=sc.nextLine();intlength=str.length();intdigit=0;Stringans="";Stringn[]=str.split("");intcrypt[]=newint[length];for(inti=0;i<length;i++){digit=Integer.parseInt(n[i]);if(digit!=9)crypt[i]=digit+1;elsecrypt[i]=0;ans=String.valueOf(crypt[i])+ans;}StringBuildersb=newStringBuilder();sb.append(ans);System.out.println(sb.reverse());}
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 →
I have this Java code. It passes all the test cases. But I dont think this is a good approach. Any suggestions on how to change it?