Java学习——Integer
来源:互联网 发布:vc编写c语言win10 编辑:程序博客网 时间:2024/05/16 01:57
1、parseInt()
String[] str = {"12","23","45"};
int sum = 0;
for(int i=0;i<str.length;i++){
int myint = Integer.parseInt(str[i]);
sum = sum+myint;
}
System.out.print("数组各元素之和是"+sum);
public static int parseInt(String s) throws NumberFormatException
'-'
('\u002D'
) to indicate a negative value or an ASCII plus sign'+'
('\u002B'
) to indicate a positive value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to theparseInt(java.lang.String, int)
method.- Parameters:
s
- aString
containing theint
representation to be parsed- Returns:
- the integer value represented by the argument in decimal.
- Throws:
NumberFormatException
- if the string does not contain a parsable integer.
2、
String str1 = Integer.toString(255);
String str2 = Integer.toBinaryString(255);
String str3 = Integer.toHexString(255);
String str4 = Integer.toOctalString(255);
System.out.print("256十进制、二进制、十六进制、八进制分别表示为:"+str1+"、"+str2+"、"+str3+"、"+str4);
运行结果:
256十进制、二进制、十六进制、八进制分别表示为:255、11111111、ff、377
toString
public static String toString(int i, int radix)
If the radix is smaller than Character.MIN_RADIX
or larger than Character.MAX_RADIX
, then the radix 10
is used instead.
If the first argument is negative, the first element of the result is the ASCII minus character'-'
('\u002D'
). If the first argument is not negative, no sign character appears in the result.
The remaining characters of the result represent the magnitude of the first argument. If the magnitude is zero, it is represented by a single zero character'0'
('\u0030'
); otherwise, the first character of the representation of the magnitude will not be the zero character. The following ASCII characters are used as digits:
0123456789abcdefghijklmnopqrstuvwxyz
These are '\u0030'
through '\u0039'
and '\u0061'
through'\u007A'
. Ifradix
is N, then the first N of these characters are used as radix-N digits in the order shown. Thus, the digits for hexadecimal (radix 16) are0123456789abcdef
. If uppercase letters are desired, theString.toUpperCase()
method may be called on the result:Integer.toString(n, 16).toUpperCase()
- Parameters:
i
- an integer to be converted to a string.radix
- the radix to use in the string representation.- Returns:
- a string representation of the argument in the specified radix.
- See Also:
Character.MAX_RADIX
,Character.MIN_RADIX
toHexString
public static String toHexString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 16.The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in hexadecimal (base 16) with no extra leading
0
s. If the unsigned magnitude is zero, it is represented by a single zero character'0'
('\u0030'
); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as hexadecimal digits:
These are the characters0123456789abcdef
'\u0030'
through'\u0039'
and'\u0061'
through'\u0066'
. If uppercase letters are desired, theString.toUpperCase()
method may be called on the result:Integer.toHexString(n).toUpperCase()
- Parameters:
i
- an integer to be converted to a string.- Returns:
- the string representation of the unsigned integer value represented by the argument in hexadecimal (base 16).
- Since:
- JDK1.0.2
toOctalString
public static String toOctalString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 8.The unsigned integer value is the argument plus 232 if the argument is negative; otherwise, it is equal to the argument. This value is converted to a string of ASCII digits in octal (base 8) with no extra leading
0
s.If the unsigned magnitude is zero, it is represented by a single zero character
'0'
('\u0030'
); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The following characters are used as octal digits:
These are the characters01234567
'\u0030'
through'\u0037'
.- Parameters:
i
- an integer to be converted to a string.- Returns:
- the string representation of the unsigned integer value represented by the argument in octal (base 8).
- Since:
- JDK1.0.2
toBinaryString
public static String toBinaryString(int i)
Returns a string representation of the integer argument as an unsigned integer in base 2.The unsigned integer value is the argument plus 232 if the argument is negative; otherwise it is equal to the argument. This value is converted to a string of ASCII digits in binary (base 2) with no extra leading
0
s. If the unsigned magnitude is zero, it is represented by a single zero character'0'
('\u0030'
); otherwise, the first character of the representation of the unsigned magnitude will not be the zero character. The characters'0'
('\u0030'
) and'1'
('\u0031'
) are used as binary digits.- Parameters:
i
- an integer to be converted to a string.- Returns:
- the string representation of the unsigned integer value represented by the argument in binary (base 2).
- Since:
- JDK1.0.2
toString
public static String toString(int i)
Returns aString
object representing the specified integer. The argument is converted to signed decimal representation and returned as a string, exactly as if the argument and radix 10 were given as arguments to thetoString(int, int)
method.- Parameters:
i
- an integer to be converted.- Returns:
- a string representation of the argument in base 10.
- Java学习——Integer
- JAVA源码学习(1)——Integer
- Java-API学习笔记---Integer
- java源码学习2-Integer
- Integer源码学习(JAVA)
- CSAPP学习笔记——Integer Representation
- Java源码学习之Integer类(三)——好玩的位运算函数
- Java常量池——Integer
- java包装类——Integer
- java练习——Integer对象问题
- Java——Integer和int比较
- Java常量池——Integer
- 13. Roman to Integer —— Java
- [Java]JDK源码学习(2)Integer
- JAVA学习随笔(2)--Integer类
- Java源码学习之Integer类(二)——1.8新增的几个函数和变量
- Leetcode学习(24)—— Reverse Integer
- python学习——leetcode第七题Reverse Integer
- 编译器优化技术
- 20140106孤独者之旅20
- Vim快捷键总结
- 读书笔记—名言积累
- opencv学习笔记1
- Java学习——Integer
- cocos2d-x 多线程以及线程同步
- C10K 問題和 Libevent 庫簡介
- 由于没有远程桌面授权服务器可以提供许可
- 淘宝活动代码查询帐号情况
- 差距就是这样在不知不觉落开了
- 用Android-X86和VirtualBox打造高性能Android开发环境
- Qt学习---3
- vs2008下配置OpenCV2.1