Академический Документы
Профессиональный Документы
Культура Документы
, i.e.
The description and signatures of the two very most useful methods are given here:
public static int parseInt(String s) //signaturefrom Integer class
String s = 139;
int i = Integer.parseInt(s);
The method
second parameter,
where the
.
String s = 3w4br;
int base = 35;
int i = Integer.parseInt(s, base); //i = 5879187
public static double parseDouble(String s) //signaturefrom Double class
String s = 282.8026;
double d = Double.parseDouble(s);
The equivalents of these for the
and
22-2
In Lesson 14 we became familiar with some base conversion methods of the
class. They all converted
types to the
equivalent of various number systems.
Below are examples of usage where is assumed to be a
and is assumed to be an
type:
1. s = Integer.toHexString(i);
//or use Integer.toString(i, 16); see page 14-3
2. s = Integer.toOctalString(i);
//or use Integer.toString(i, 8);
3. s = Integer.toBinaryString(i);
//or use Integer.toString(i, 2);
A description of each is given followed by the method signature and then an example of
usage:
; //Signaturefrom Integer class
//See 1, 2, & 3 above for a two-parameter
version.
int i = 104;
String ss = Integer.toString(i);
You should be aware that there is an easier way to convert an integer into a
. Just append an
type to an empty
and the compiler will think
you want to make a
out of the combination.
int j = 3;
String s = + j; // s will be equal to 3
s = + 56;
// s will be equal to 56
//Signaturefrom Integer class
String s = 452;
Integer iObj = Integer.valueOf(s);
class
Data member constants of the
has a value of -2,147,483,648
has a value of 2,147,483,647
These two constants (see Appendix C) give the two extreme possible values of
variables.