Convert Long to numeric primitive data types example
1.
/*
2.
Convert Long to numeric primitive data types example
3.
This example shows how a Long object can be converted into below given numeric
4.
data types
5.
- Convert Long to byte
6.
- Convert Long to short
7.
- Convert Long to int
8.
- Convert Long to float
9.
- Convert Long to double
10.
*/
11.
12.
public class LongToNumericPrimitiveTypesExample {
13.
14.
public static void main(String[] args) {
15.
Long lObj = new Long("10");
16.
//use byteValue method of Long class to convert it into byte type.
17.
byte b = lObj.byteValue();
18.
System.out.println(b);
19.
20.
//use shortValue method of Long class to convert it into short type.
21.
short s = lObj.shortValue();
22.
System.out.println(s);
23.
24.
//use intValue method of Long class to convert it into int type.
25.
int i = lObj.intValue();
26.
System.out.println(i);
27.
28.
//use floatValue method of Long class to convert it into float type.
29.
float f = lObj.floatValue();
30.
System.out.println(f);
31.
32.
//use doubleValue method of Long class to convert it longo double type.
33.
double d = lObj.doubleValue();
34.
System.out.println(d);
35.
}
36.
}
37.
38.
/*
39.
Output of the program would be :
40.
10
41.
10
42.
10
43.
10.0
44.
10.0
45.
*/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.