1// String to hexadecimal in java
2import java.util.Scanner;
3public class StringToHexJava
4{
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8 System.out.println("Please enter a string: ");
9 String strInput = sc.next();
10 StringBuffer sb = new StringBuffer();
11 char[] chArray = strInput.toCharArray();
12 for(int a = 0; a < chArray.length; a++)
13 {
14 String strHexadecimal = Integer.toHexString(chArray[a]);
15 sb.append(strHexadecimal);
16 }
17 String strOutput = sb.toString();
18 System.out.println(strOutput);
19 sc.close();
20 }
21}