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.
importjava.io.*;importjava.util.*;importjava.security.MessageDigest;importjava.math.BigInteger;publicclassSolution{publicstaticvoidmain(String[]args)throwsException{Scannerscan=newScanner(System.in);Stringstr=scan.nextLine();scan.close();try{// Static getInstance method is called with hashing MD5MessageDigestmd=MessageDigest.getInstance("MD5");// digest() method is called to calculate message digest// of an input digest() return array of bytebyte[]messageDigest=md.digest(str.getBytes());// Convert byte array into signum representationBigIntegerno=newBigInteger(1,messageDigest);// Convert message digest into hex valueStringhashtext=no.toString(16);while(hashtext.length()<32){hashtext="0"+hashtext;}System.out.println(hashtext);}// For specifying wrong message digest algorithmscatch(Exceptione){thrownewException(e);}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java MD5
You are viewing a single comment's thread. Return to all comments →