Crenox

Data Types in Java

May 15th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. package com.samkough.java.main;
  2.  
  3. public class Integers
  4. {
  5. public static void main(String args[])
  6. {
  7. // This line creates an integer primitive data type.
  8. int a = 55;
  9. // An Integer wrapper class is created from the primitive int type.
  10. Integer b = new Integer(a);
  11.  
  12. // The intValue() method converts the Integer to int. Likewise, the floatValue() returns a float data type.
  13. int c = b.intValue();
  14. float d = b.floatValue();
  15.  
  16. // These three methods return a binary, hexadecimal and octal representations of the integer.
  17. String bin = Integer.toBinaryString(a);
  18. String hex = Integer.toHexString(a);
  19. String oct = Integer.toOctalString(a);
  20.  
  21. System.out.println(a);
  22. System.out.println(b);
  23. System.out.println(c);
  24. System.out.println(d);
  25.  
  26. System.out.println(bin);
  27. System.out.println(hex);
  28. System.out.println(oct);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment