package huawei;
/**
华为面试题库HJ5
进制数转换问题
*
* @author ZengWenFeng
* @date 2023.03.01
* @mobile 13805029595
* @email 117791303@QQ.COM
*/
public class HJ_005_INT_PARSE
{
/**
* java.lang.Integer
*
* Parses the string argument as a signed integer in the radix
* specified by the second argument. The characters in the string
* must all be digits of the specified radix (as determined by
* whether {@link java.lang.Character#digit(char, int)} returns a
* nonnegative value), except that the first character may be an
* ASCII minus sign {@code '-'} ({@code '\u005Cu002D'}) to
* indicate a negative value or an ASCII plus sign {@code '+'}
* ({@code '\u005Cu002B'}) to indicate a positive value. The
* resulting integer value is returned.
*
* <p>An exception of type {@code NumberFormatException} is
* thrown if any of the following situations occurs:
* <ul>
* <li>The first argument is {@code null} or is a string of
* length zero.
*
* <li>The radix is either smaller than
* {@link java.lang.Character#MIN_RADIX} or
* larger than {@link java.lang.Character#MAX_RADIX}.
*
* <li>Any character of the string is not a digit of the specified
* radix, except that the first character may be a minus sign
* {@code '-'} ({@code '\u005Cu002D'}) or plus sign
* {@code '+'} ({@code '\u005Cu002B'}) provided that the
* string is longer than length 1.
*
* <li>The value represented by the string is not a value of type
* {@code int}.
* </ul>
*
* <p>Examples:
* <blockquote><pre>
* parseInt("0", 10) returns 0
* parseInt("473", 10) returns 473
* parseInt("+42", 10) returns 42
* parseInt("-0", 10) returns 0
* parseInt("-FF", 16) returns -255
* parseInt("1100110", 2) returns 102
* parseInt("2147483647", 10) returns 2147483647
* parseInt("-2147483648", 10) returns -2147483648
* parseInt("2147483648", 10) throws a NumberFormatException
* parseInt("99", 8) throws a NumberFormatException
* parseInt("Kona", 10) throws a NumberFormatException
* parseInt("Kona", 27) returns 411787
* </pre></blockquote>
*
* @param s the {@code String} containing the integer
* representation to be parsed
* @param radix the radix to be used while parsing {@code s}.
* @return the integer represented by the string argument in the
* specified radix.
* @exception NumberFormatException if the {@code String}
* does not contain a parsable {@code int}.
*/
/**
* Integer.parseInt(String s, int radix)
*
* public static int parseInt(String s, int radix)
*
* @author ZengWenFeng
* @date 2023.03.01
* @mobile 13805029595
* @email 117791303@QQ.COM
* @param ZengWenFeng13805029595
*/
public static void main(String[] ZengWenFeng13805029595)
{
String str2 = "0000000000000011";
System.out.println(Integer.parseInt(str2, 2));
String str3 = "0000000000000021";
System.out.println(Integer.parseInt(str3, 3));
String str11 = "0000000000000021A";
System.out.println(Integer.parseInt(str11, 11));
String str12 = "000000000000002AB";
System.out.println(Integer.parseInt(str12, 12));
}
}
HJ_005_INT_PARSE.java
最新推荐文章于 2024-07-22 14:15:06 发布