2012-06-30 4 views

답변

2

예.

Byte.parseByte(s); -- parses a Byte from a String 
Short.parseShort(s); -- parses a Short from a String 

그리고 더 큰 숫자있다 :있다

Long.parseLong(s); 
-- Float is an imprecise representation of a floating point number using 32 bits 
Float.parseFloat(s); 
-- Double is an imprecise representation of a floating point number using 64 bits 
Double.parseDouble(s); 
-- BigIntegers is an integer of arbitrary size as is accurate 
new BigInteger(s); 
-- BigDecimal is a floating point number of arbitrary size as is accurate 
new BigDecimal(s); 
+0

다음 오류가 발생합니다. int i4 = new BigInteger (args [3]); 타입 불일치 : BigInteger에서 int로 변환 할 수 없다 –

+1

'BigInteger'에서'int'를 얻으려면'.intValue()'를 사용하십시오 :'i4 = new BigInteger (s) .intValue();'. BigInteger 클래스는 임의로 큰 숫자에 대해 정확한 정수 연산을 수행하기위한 클래스입니다. 그러한 산술을위한 특별한 방법을 가지고 있습니다. – Bohemian

0

다른 방법은 String의 정수를 얻을 :

String value = "2"; 

    int i = Integer.valueOf(value); 
    System.out.println("i = " + i); 
    Scanner scanner = new Scanner(value); 
    i = scanner.nextInt(); 
    System.out.println("i = " + i); 
0

또한 그렇게 시도의 catch 블록에서 그 포장한다 정수가 아닌 값을 전달하려고하면 코드가 파열되지 않습니다.

관련 문제