Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment: {Write a program called DisplayNumberSystems (DisplayNumberSystems.j

ID: 641022 • Letter: A

Question

Assignment:

{Write a program called DisplayNumberSystems (DisplayNumberSystems.java) that will display a formatted table of the binary, octal, and hexadecimal equivalents of the decimal number enter (up to a maximum of 1024). The program will need to include/use the following methods:

Method Signature
convertToBinary public static String convertToBinary( int )

convertToOctal public static String convertToOctal( int )

convertToHex public static String convertToHex( int )

Sample Run:

java DisplayNumberSystem

}

My Issue:

My program wont return anything but repetitive columns of-

Decimal Binary Octal Hexadecimal

Decimal Binary Octal Hexadecimal

Decimal Binary Octal Hexadecimal

Decimal Binary Octal Hexadecimal

etc....

}

Here is the code I have written:

import java.lang.*;

import java.util.Scanner;

public class DisplayNumberSystems{

   public static String convertedToBinary(int number){
       return Integer.toBinaryString(number);
   }
  
   public static String convertedToOctal(int number){
       return Integer.toOctalString(number);
   }

   public static String convertedToHex(int number){
       return Integer.toHexString(number);
   }


   public static void main(String [] args){

       Scanner d = new Scanner(System.in);
  
       System.out.println("Enter decimal value to display to: ");

       int dec = d.nextInt();

       String Decimal = d.nextLine();

       String Binary = Integer.toBinaryString(bin);

       String Octal = Integer.toOctalString(oct);

       String Hexadecimal = Integer.toHexString(hex);

           for (int i = 1; i <= dec; i++){

           System.out.printf("%-10s %-10s %-10s %-10s ","Decimal","Binary","Octal","Hexadecimal");

               convertedToBinary(dec);

               convertedToOctal(dec);

               convertedToHex(dec);

       }

   }

}

Can anyone tell me how to fix this?

Explanation / Answer

Note : The changes required to execute are in Bold... please find it

---------------------------------------------------------------------------------------------------------------------

import java.util.Scanner;

public class DisplayNumberSystems{

public static String convertedToBinary(int number){
return Integer.toBinaryString(number);
}
  
public static String convertedToOctal(int number){
return Integer.toOctalString(number);
}

public static String convertedToHex(int number){
return Integer.toHexString(number);
}


public static void main(String [] args){

Scanner d = new Scanner(System.in);
  
System.out.println("Enter decimal value to display to: ");

int dec = d.nextInt();

//String Decimal = d.nextLine();

//String Binary = Integer.toBinaryString(dec);

//String Octal = Integer.toOctalString(dec);

//String Hexadecimal = Integer.toHexString(dec);

System.out.printf("%-10s %-10s %-10s %-10s ","Decimal","Binary","Octal","Hexadecimal");
  
for (int i = 1; i <= dec; i++){
  
   System.out.printf("%-10s %-10s %-10s %-10s ",i,convertedToBinary(i),convertedToOctal(i),convertedToHex(i));
}
  
d.close();

}

}

Ouptut :

Enter decimal value to display to:
15
Decimal Binary Octal Hexadecimal
1 1 1 1   
2 10 2 2   
3 11 3 3   
4 100 4 4   
5 101 5 5   
6 110 6 6   
7 111 7 7   
8 1000 10 8   
9 1001 11 9   
10 1010 12 a   
11 1011 13 b   
12 1100 14 c   
13 1101 15 d   
14 1110 16 e   
15 1111 17 f   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote