Sys.java - public class Sys public static void main(String args System.out.printf-12s-12s-12s-12s\\n\"Decimal\"Binary\"Octal\"Hexadecimal for(int

Sys.java - public class Sys public static void main(String...

This preview shows page 1 out of 1 page.

public class Sys { public static void main(String[] args) { System.out.printf( "%-12s%-12s%-12s%-12s\n", "Decimal", "Binary", "Octal", "Hexadecimal" ); for (int i=1;i<=256;i++){ String binary=ToBinary(i); String octal=ToOctal(i); String hexadecimal=ToHexadecimal(i); System.out.printf( "%-12d%-12s%-12s%-12s\n", i, binary, octal, hexadecimal ); } } public static String ToBinary(int num){ String binary=""; while(num>=1){ int ans=num%2; binary=ans+binary; num=num/2; } return binary; } public static String ToOctal(int num){ String octal=""; while(num>=1){ int ans=num%8;
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

  • Spring '17
  • Ijlal

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture