Java by API/java.lang/Short
Содержание
new Short(short value)
<source lang="java">
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); }
}
</source>
new Short(String s)
<source lang="java">
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); }
}
</source>
Short: byteValue()
<source lang="java">
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
- /
</source>
Short: doubleValue()
<source lang="java">
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
- /
</source>
Short: floatValue()
<source lang="java">
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
- /
</source>
Short: intValue()
<source lang="java">
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
- /
</source>
Short: longValue()
<source lang="java">
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
- /
</source>
Short.MAX_VALUE
<source lang="java">
/* 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++); }
}
</source>
Short: parseShort(String s,int radix )
<source lang="java">
/*
* 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); }
}
</source>
Short: shortValue()
<source lang="java">
public class MainClass {
public static void main(String[] args) { short s = -1800; Short s2 = new Short(s); System.out.println(s2.shortValue()); }
}
</source>
Short: toString()
<source lang="java">
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); }
}
</source>
Short: valueOf(String stringValue)
<source lang="java">
/*
* 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); }
}
</source>