PackageCom.lei.duixiang; Public classSummation {/*** Type conversion * Constant integer Boolean Byte Character Double number * Just as an instance of integer, basically the same as * Max_value (indicates in T type desirable maximum) * Min_value (denotes the minimum value of the int type) * SIZE (the number of digits used to represent the int value in twos complement form) * Type (class instance of the base type int) * @paramargs*/ Public Static voidMain (string[] args) {String str[]= {"10", "20", "30", "40", "50"};//defining a string array intsum = 0; for(intI=0;i < str.length;i++){ intMyint = Integer.parseint (Str[i]);//convert each array to intsum = sum +Myint; } System.out.println ("The sum of each element in the array is:" +sum); String S1= Integer.tostring (456);//Decimal RepresentationString s2 = integer.tobinarystring (456);//Binary RepresentationString s3 = integer.tohexstring (456);//hexadecimal representationString S4 = integer.tooctalstring (456);//octal indicatesSystem.out.println (The decimal representation of "456" is: "+S1); System.out.println (The binary representation of 456 is: "+S2); System.out.println (The hexadecimal representation of 456 is: "+S3); System.out.println (The octal representation of 456 is: "+S4); //Integer Constantssummation s =Newsummation (); S.getcon (); //Boolean constantS.getboolean (); //Byte Constant MethodS.getbyte (); //Character Constant MethodS.getcharacter (); } //Integer Constant Method Public voidGetcon () {System.out.println ("-----------------"); /*** The Integer class provides 4 constants * Max_value (indicates the maximum value desirable for int type) * Min_value (indicates the minimum value of int type) * SI ZE (the number of bits used to represent the int value in the form of twos complement) * TYPE (class instance of the base type int)*/ intMaxint = Integer.max_value;//gets the constant value of an integer intMinint =Integer.min_value; intIntsize =integer.size; System.out.println ("The maximum value that is desirable for an int type is:" +maxint); System.out.println (The minimum value that is desirable for the int type is: "+minint); System.out.println ("The number of bits that the int type is desirable is:" +intsize); } //Boolean Constant Method Public voidGetboolean () {System.out.println ("-----------------"); /*** Boolean class provides 3 constants * 1, type (class instance of base type Boolean) * 2, False (Boolean object corresponding to base value false) * 3, True (Boolean object corresponding to the base value true)*/Boolean B1=NewBoolean (true);//Create a Boolean objectBoolean B2 =NewBoolean ("OK"); System.out.println ("B1:" +B1.booleanvalue ()); System.out.println ("B2:" +B2.booleanvalue ()); } //Byte Constant Method Public voidGetByte () {System.out.println ("-----------------"); byteMyByte = 45; Byte b=NewByte (MyByte); Byte a=NewByte ("12"); Byte Maxbyte= Byte.max_value;//gets the constant value of an integerByte Minbyte =Byte.min_value; Byte ByteSize=byte.size; System.out.println ("The maximum value that is desirable for a Byte type is:" +maxbyte); System.out.println ("The minimum value that is desirable for a Byte type is:" +minbyte); System.out.println ("The number of bits the Byte type is desirable is:" +bytesize); System.out.println (B.bytevalue ()); System.out.println (A.bytevalue ()); } //Character Constant Method Public voidGetcharacter () {System.out.println ("-----------------"); Character mychar1=NewCharacter (' A '); Character mychar2=NewCharacter (' a '); System.out.println (Mychar1+ "Is it an uppercase letter?" "+character.isuppercase (MYCHAR1)); System.out.println (Mychar1+ "Is it a lowercase letter?" "+character.islowercase (MYCHAR2)); }}
12. Type conversions and Constants