----------------------------------------------------------------------------------------
It seems that the int type will not exceed, but ...
----------------------------------------------------------------------------------------
Algorithm
1 /*Problem Description2 Enter a positive hexadecimal number string that does not exceed 8 bits from the keyboard, converting it to a positive decimal number after the output. 3 Note: 10~15 in hexadecimal numbers are denoted by uppercase letters A, B, C, D, E, F, respectively. 4 Sample Input5 FFFF6 Sample Output7 65535*/8 ImportJava.util.*;9 Public classMain {Ten Public Static voidMain (string[] args) { OneString st =NewScanner (system.in). nextline (); ASystem.out.println (Long.parselong (St, 16)); - } -}
Learning Supplement
Integer class
static int parseint (String s)//将字符串参数作为有符号的十进制整数进行解析
static int parseint (String s,int radix)//resolves the string argument to a signed integer using the cardinality specified by the second parameter. Returns a decimal integer (radix represents a binary)
Example:
parseint ("0", 10) returns 0
parseint ("473", 10) returns 473
parseint ("0", 10) returns 0
parseint ("-ff", 16) return-255
parseint ("1100110", 2) returns 102
parseint ("2147483647", 10) returns 2147483647
parseint ("2147483648", 10) return-2147483648
parseint ("2147483648", 10) throws NumberFormatException
parseint ("99", 8) throws NumberFormatException
parseint ("Kona", 10) throws NumberFormatException
parseint ("Kona", 27) return 411787
Long class
Static Long Parselong (string s)//resolves the String argument to a signed decimallong
Static Long Parselong (String s,int radix)//resolves the String parameter to a signed long
, cardinality specified by the second parameter returns a decimal long
Basic Practice hex to Decimal