Java by API/java.lang/Integer
Содержание
- 1 Integer: bitCount(int i)
- 2 Integer: equals(Object obj)
- 3 Integer: highestOneBit(int i)
- 4 Integer: Integer.SIZE
- 5 Integer: intValue()
- 6 Integer: lowestOneBit(int i)
- 7 Integer.MAX_VALUE
- 8 Integer: MIN_VALUE
- 9 Integer: numberOfLeadingZeros(int i)
- 10 Integer: numberOfTrailingZeros(int i)
- 11 Integer: parseInt(String stringValue)
- 12 Integer: reverseBytes(int i)
- 13 Integer: rotateLeft(int i, int distance)
- 14 Integer: signum(int i)
- 15 Integer: toBinaryString(int intValue)
- 16 Integer: toHexString(int intValue)
- 17 Integer: toOctalString(int intValue)
- 18 Integer: valueOf(String stringValue)
Integer: bitCount(int i)
<source lang="java">
import java.io.IOException; public class MainClass {
public static void main(String args[]) throws IOException { int n = 170; // 10101010 System.out.println("Value in binary: 10101010"); System.out.println("Number of one bits: " + Integer.bitCount(n)); System.out.println("Highest one bit: " + Integer.highestOneBit(n)); System.out.println("Lowest one bit: " + Integer.lowestOneBit(n)); System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n)); System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n)); System.out.println("\nBeginning with the value 1, " + "rotate left 16 times."); n = 1; for (int i = 0; i < 16; i++) { n = Integer.rotateLeft(n, 1); System.out.println(n); } }
}
</source>
Integer: equals(Object obj)
<source lang="java">
/*
* Output:
true
*/
public class MainClass {
public static void main(String args[]) { Integer iobj1 = new Integer(5); Integer iobj2 = new Integer("5"); System.out.println(iobj1.equals(iobj2)); }
}
</source>
Integer: highestOneBit(int i)
<source lang="java">
import java.io.IOException; public class MainClass {
public static void main(String args[]) throws IOException { int n = 170; // 10101010 System.out.println("Value in binary: 10101010"); System.out.println("Number of one bits: " + Integer.bitCount(n)); System.out.println("Highest one bit: " + Integer.highestOneBit(n)); System.out.println("Lowest one bit: " + Integer.lowestOneBit(n)); System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n)); System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n)); System.out.println("\nBeginning with the value 1, " + "rotate left 16 times."); n = 1; for (int i = 0; i < 16; i++) { n = Integer.rotateLeft(n, 1); System.out.println(n); } }
}
</source>
Integer: Integer.SIZE
<source lang="java">
public class Main {
public static void main(String[] arg) { System.out.println(Integer.SIZE); }
}
</source>
Integer: intValue()
<source lang="java">
/*
* Output:
i1 = 5 i2 = 6
*/
public class MainClass {
public static void main(String args[]) { Integer iobj1 = new Integer(5); Integer iobj2 = new Integer("6"); int i1 = iobj1.intValue(); int i2 = iobj2.intValue(); System.out.println("i1 = " + i1); System.out.println("i2 = " + i2); }
}
</source>
Integer: lowestOneBit(int i)
<source lang="java">
import java.io.IOException; public class MainClass {
public static void main(String args[]) throws IOException { int n = 170; // 10101010 System.out.println("Value in binary: 10101010"); System.out.println("Number of one bits: " + Integer.bitCount(n)); System.out.println("Highest one bit: " + Integer.highestOneBit(n)); System.out.println("Lowest one bit: " + Integer.lowestOneBit(n)); System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n)); System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n)); System.out.println("\nBeginning with the value 1, " + "rotate left 16 times."); n = 1; for (int i = 0; i < 16; i++) { n = Integer.rotateLeft(n, 1); System.out.println(n); } }
}
</source>
Integer.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>
Integer: MIN_VALUE
<source lang="java">
public class Main {
public static void main(String[] arg) { System.out.println(Integer.MAX_VALUE); System.out.println(Integer.MIN_VALUE); }
}
</source>
Integer: numberOfLeadingZeros(int i)
<source lang="java">
import java.io.IOException; public class MainClass {
public static void main(String args[]) throws IOException { int n = 170; // 10101010 System.out.println("Value in binary: 10101010"); System.out.println("Number of one bits: " + Integer.bitCount(n)); System.out.println("Highest one bit: " + Integer.highestOneBit(n)); System.out.println("Lowest one bit: " + Integer.lowestOneBit(n)); System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n)); System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n)); System.out.println("\nBeginning with the value 1, " + "rotate left 16 times."); n = 1; for (int i = 0; i < 16; i++) { n = Integer.rotateLeft(n, 1); System.out.println(n); } }
}
</source>
Integer: numberOfTrailingZeros(int i)
<source lang="java">
import java.io.IOException; public class MainClass {
public static void main(String args[]) throws IOException { int n = 170; // 10101010 System.out.println("Value in binary: 10101010"); System.out.println("Number of one bits: " + Integer.bitCount(n)); System.out.println("Highest one bit: " + Integer.highestOneBit(n)); System.out.println("Lowest one bit: " + Integer.lowestOneBit(n)); System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n)); System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n)); System.out.println("\nBeginning with the value 1, " + "rotate left 16 times."); n = 1; for (int i = 0; i < 16; i++) { n = Integer.rotateLeft(n, 1); System.out.println(n); } }
}
</source>
Integer: parseInt(String stringValue)
<source lang="java">
/*
* Output:
Sum is 8
*/
public class MainClass {
public static void main(String args[]) { int i = Integer.parseInt("3"); int j = Integer.parseInt("5"); int sum = i + j; System.out.print("Sum is " + sum); }
}
</source>
Integer: reverseBytes(int i)
<source lang="java">
public class Main {
public static void main(String args[]) { System.out.println(Integer.reverseBytes(10)); System.out.println(Integer.reverseBytes(-10)); System.out.println(Integer.reverseBytes(0)); }
}
</source>
Integer: rotateLeft(int i, int distance)
<source lang="java">
import java.io.IOException; public class MainClass {
public static void main(String args[]) throws IOException { int n = 170; // 10101010 System.out.println("Value in binary: 10101010"); System.out.println("Number of one bits: " + Integer.bitCount(n)); System.out.println("Highest one bit: " + Integer.highestOneBit(n)); System.out.println("Lowest one bit: " + Integer.lowestOneBit(n)); System.out.println("Number of leading zeros : " + Integer.numberOfLeadingZeros(n)); System.out.println("Number of trailing zeros : " + Integer.numberOfTrailingZeros(n)); System.out.println("\nBeginning with the value 1, " + "rotate left 16 times."); n = 1; for (int i = 0; i < 16; i++) { n = Integer.rotateLeft(n, 1); System.out.println(n); } }
}
</source>
Integer: signum(int i)
<source lang="java">
public class Main {
public static void main(String args[]) { System.out.println(Integer.signum(10)); System.out.println(Integer.signum(-10)); System.out.println(Integer.signum(0)); }
}
</source>
Integer: toBinaryString(int intValue)
<source lang="java">
/*
* Output:
Binary is 1011
*/
public class MainClass {
public static void main(String args[]) { int i = 11; System.out.println("Binary is " + Integer.toBinaryString(i)); }
}
</source>
Integer: toHexString(int intValue)
<source lang="java">
/*
* Output:
Hex is b
*/
public class MainClass {
public static void main(String args[]) { int i = 11; System.out.println("Hex is " + Integer.toHexString(i)); }
}
</source>
Integer: toOctalString(int intValue)
<source lang="java">
/*
* Output:
Octal is 13
*/
public class MainClass {
public static void main(String args[]) { int i = 11; System.out.println("Octal is " + Integer.toOctalString(i)); }
}
</source>
Integer: 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>