![]() Int number4 = Integer.valueOf(string4, 8) Int number3 = Integer.valueOf(string3, 32) The valueOf() method, unlike the parseInt() method, returns an Integer instead of a primitive int and also throws a NumberFormatException if the String cannot be converted properly and only accepts decimal numbers: int i = 10 valueOf(String s, int radix) - Accepts a String and returns an Integer representing the value and then parses it with the given base.valueOf(int i) - Accepts an int and parses it into an Integer.valueOf(String s) - Accepts a String and parses it into an Integer.Parsing String "Google" in base 32: 562840238 Running this piece of code will yield: Parsing String "100": 100 ( "Parsing String \"" + string4 + "\" in base 8: " + number4) ( "Parsing String \"" + string3 + "\" in base 32: " + number3) ( "Parsing String \"" + string2 + "\" in base 16: " + number2) ( "Parsing String \"" + string1 + "\": " + number1) Int number4 = Integer.parseInt(string4, 8) Int number3 = Integer.parseInt(string3, 32) Int number2 = Integer.parseInt(string2, 16) The parseInt() method converts the input String into a primitive int and throws a NumberFormatException if the String cannot be converted: String string1 = "100" ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |