Java by API/java.lang/Short — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Содержание
new Short(short value)
public class Main {
public static void main(String[] args) {
short s = 10;
Short sObj1 = new Short(s);
Short sObj2 = new Short("10");
System.out.println(sObj1);
System.out.println(sObj2);
}
}
new Short(String s)
public class Main {
public static void main(String[] args) {
short s = 10;
Short sObj1 = new Short(s);
Short sObj2 = new Short("10");
System.out.println(sObj1);
System.out.println(sObj2);
}
}
Short: byteValue()
public class Main {
public static void main(String[] args) {
Short sObj = new Short("10");
byte b = sObj.byteValue();
System.out.println(b);
short s = sObj.shortValue();
System.out.println(s);
int i = sObj.intValue();
System.out.println(i);
float f = sObj.floatValue();
System.out.println(f);
double d = sObj.doubleValue();
System.out.println(d);
long l = sObj.longValue();
System.out.println(l);
}
}
/*
10
10
10
10.0
10.0
10
*/
Short: doubleValue()
public class Main {
public static void main(String[] args) {
Short sObj = new Short("10");
byte b = sObj.byteValue();
System.out.println(b);
short s = sObj.shortValue();
System.out.println(s);
int i = sObj.intValue();
System.out.println(i);
float f = sObj.floatValue();
System.out.println(f);
double d = sObj.doubleValue();
System.out.println(d);
long l = sObj.longValue();
System.out.println(l);
}
}
/*
10
10
10
10.0
10.0
10
*/
Short: floatValue()
public class Main {
public static void main(String[] args) {
Short sObj = new Short("10");
byte b = sObj.byteValue();
System.out.println(b);
short s = sObj.shortValue();
System.out.println(s);
int i = sObj.intValue();
System.out.println(i);
float f = sObj.floatValue();
System.out.println(f);
double d = sObj.doubleValue();
System.out.println(d);
long l = sObj.longValue();
System.out.println(l);
}
}
/*
10
10
10
10.0
10.0
10
*/
Short: intValue()
public class Main {
public static void main(String[] args) {
Short sObj = new Short("10");
byte b = sObj.byteValue();
System.out.println(b);
short s = sObj.shortValue();
System.out.println(s);
int i = sObj.intValue();
System.out.println(i);
float f = sObj.floatValue();
System.out.println(f);
double d = sObj.doubleValue();
System.out.println(d);
long l = sObj.longValue();
System.out.println(l);
}
}
/*
10
10
10
10.0
10.0
10
*/
Short: longValue()
public class Main {
public static void main(String[] args) {
Short sObj = new Short("10");
byte b = sObj.byteValue();
System.out.println(b);
short s = sObj.shortValue();
System.out.println(s);
int i = sObj.intValue();
System.out.println(i);
float f = sObj.floatValue();
System.out.println(f);
double d = sObj.doubleValue();
System.out.println(d);
long l = sObj.longValue();
System.out.println(l);
}
}
/*
10
10
10
10.0
10.0
10
*/
Short.MAX_VALUE
/*
i=32767
i=-32768
i=-32767
i=2147483647
i=-2147483648
i=-2147483647
*/
public class MainClass {
public static void main(String[] unused) {
do_shorts();
do_ints();
}
protected static void do_shorts() {
short i = Short.MAX_VALUE;
System.out.println("i=" + i++);
System.out.println("i=" + i++);
System.out.println("i=" + i++);
}
protected static void do_ints() {
int i = Integer.MAX_VALUE;
System.out.println("i=" + i++);
System.out.println("i=" + i++);
System.out.println("i=" + i++);
}
}
Short: parseShort(String s,int radix )
/*
* Output:
The sum is 254
*/
public class MainClass {
public static void main(String args[]) {
String strOctal = "77";
String strHex = "23";
String strDecimal = "156";
short o = Short.parseShort(strOctal, 8);
short h = Short.parseShort("23", 16);
short d = Short.parseShort(strDecimal, 10);
int sum = o + h + d;
System.out.println("The sum is " + sum);
}
}
Short: shortValue()
public class MainClass {
public static void main(String[] args) {
short s = -1800;
Short s2 = new Short(s);
System.out.println(s2.shortValue());
}
}
Short: toString()
public class Main {
public static void main(String[] args) {
short s = 10;
Short sObj = new Short(s);
String str = sObj.toString();
System.out.println(str);
}
}
Short: valueOf(String stringValue)
/*
* Output:
true
c
12
2
13245
12341234
11234.123
4.321324123412341E10
*/
public class MainClass {
public static void main(String args[]) {
Boolean bool = Boolean.valueOf("true");
Character c = new Character("c");
Byte b = Byte.valueOf("12");
Short s = Short.valueOf("2");
Integer i = Integer.valueOf("13245");
Long l = Long.valueOf("12341234");
Float f = Float.valueOf("11234.1234");
Double d = Double.valueOf("43213241234.123412341234");
System.out.println(bool);
System.out.println(c);
System.out.println(b);
System.out.println(s);
System.out.println(i);
System.out.println(l);
System.out.println(f);
System.out.println(d);
}
}