Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import static java.lang.System.out;
  2.  
  3. public class DecimalEquivalents {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. new DecimalEquivalents().binaryCounter();
  8.  
  9. }//end main()
  10.  
  11. public void binaryCounter() {
  12.  
  13. //count 0-100 in Binary:
  14. for(byte i = 0b00; i <= 0b1100100; i++) {
  15.  
  16. try {
  17.  
  18. Thread.sleep(250);
  19.  
  20. } catch(InterruptedException ie) {
  21.  
  22. out.println("oops! something went wrong !");
  23. out.println(ie.getMessage());
  24.  
  25. }//end try/catch
  26.  
  27. out.println("Nums Represented in Binary: " + Integer.toBinaryString(i));
  28. out.println("Decimal equivalent: \t " + i);
  29.  
  30. out.println("Octal equivalent: \t " + Integer.toOctalString(i));
  31. out.println("Hexadecimal equiv: \t " + Integer.toHexString(i));
  32.  
  33. out.println();
  34.  
  35. }//end 4Loop
  36.  
  37. }//end binaryCounter()
  38.  
  39. }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement