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.text.*;importjava.math.*;importjava.util.regex.*;importjava.security.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scanners=newScanner(System.in);Stringstr;booleanresult=false;while(s.hasNext()){str=s.nextLine().trim();result=Pattern.matches("^[a-zA-Z0-9]+$",str);if(result){try{MessageDigestmd=MessageDigest.getInstance("MD5");md.update(str.getBytes());byte[]digest=md.digest();for(byteb:digest){System.out.printf("%02x",b);}System.out.println();}catch(Exceptione){}}else{System.out.println("Invalid Input!");}}s.close();}}
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
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.; import java.security.;
public class Solution {
}
works well for java7, java8, java15 import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Scanner;
public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); sc.close();
}
import java.io.; import java.util.; import java.security.MessageDigest; import java.math.BigInteger;
public class Solution {
}