Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1.  
  2. import java.util.*;
  3. import java.io.*;
  4. import java.math.*;
  5. import java.util.Scanner;
  6.  
  7. public class HexToDecimal {
  8.  
  9. public static void main(String[] args) {
  10. System.out.print("Hexadecimal Input:");
  11.  
  12. Scanner s = new Scanner(System.in);
  13. String inputHex = s.nextLine();
  14. try{
  15.  
  16. Integer outputDecimal = Integer.parseInt(inputHex, 16);
  17. System.out.println("Decimal Equivalent : "+outputDecimal);
  18. }
  19. catch(NumberFormatException ne){
  20.  
  21. System.out.println("Invalid Input");
  22. }
  23. finally{
  24. s.close();
  25. }
  26.  
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement