Question

In: Computer Science

Write a java program of a multiplication table of binary numbers using a 2D array of...

Write a java program of a multiplication table of binary numbers using a 2D array of integers.

Solutions

Expert Solution


public class Main
{
//method to convert decimal into binary
public static int decimalToBinary(int decimalnum)
{
int binarynum = 0, rem, temp = 1;
  
while (decimalnum!=0)
{
rem = decimalnum %2;
decimalnum = decimalnum / 2;
binarynum = binarynum + rem*temp;
temp = temp * 10;
}
  
//return number
return binarynum;
}
  
public static void main(String[] args)
{
//2d array declaration
int[][] mulTable = new int[10][10];
int r = 1;
int c = 1;
  
//fill the binary array
for(int a = 0; a < mulTable.length; a++)
{
for(int b = 0; b < mulTable[a].length; b++)
{
int num = r * c;
mulTable[a][b] = decimalToBinary(num);
c++;
}
r++;
c = 1;
}
  
//display the binary array
for(int a = 0; a < mulTable.length; a++)
{
System.out.printf("%4d:", mulTable[a][0]);
for(int b = 0; b < mulTable[a].length; b++)
{
System.out.printf("%8d", mulTable[a][b]);
}
System.out.print("\n");
}
}
}

OUTPUT:


Related Solutions

Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
java 2D array / recursion explain every method You are requested to write a Java program...
java 2D array / recursion explain every method You are requested to write a Java program of a simple Memory Management Unit. The program should allow the following: 1. The user can create a process asking for memory. The program will return a process ID if the requested memory can be allocated. It will also print the allocated Base and Limit. 2. The user can delete a process by specifying a process ID. The program should do that and free...
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers....
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers. Start your code by copying/pasting this information into an editor like notepad, notepad++, or IDLE: public class Main { public static void main(String[] args) { // Write your code here } } Sample input: Input first number: 125 Input second number: 24 Sample Output: 125 + 24 = 149 125 - 24 = 101 125 x 24 = 3000 125 / 24 = 5...
i want a program in java that finds the shortest path in a 2D array with...
i want a program in java that finds the shortest path in a 2D array with obstacles from source to destination using BFS and recursion. The path must be stored in a queue. The possible moves are left,right,up and down.
Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
java 1.) a method to append a 2d double array at the right of another 2d...
java 1.) a method to append a 2d double array at the right of another 2d double array, return a new array. E.g. numss1: {{1, 2}, {3, 4, 5}, {6}}, numss2: {{7}, {8, 9}}, return {{1, 2, 7}, {3, 4, 5, 8, 9}, {6}}
Description: You are to develop a Java program that prints out the multiplication or addition table...
Description: You are to develop a Java program that prints out the multiplication or addition table given the users start and end range and type of table. This time several classes will be used. You are free to add more methods as you see fit – but all the methods listed below must be used in your solution. For the class Table the following methods are required: - Protected Constructor – stores the start and size of table, creates the...
Using Java Write a program that reads a file of numbers of type int and outputs...
Using Java Write a program that reads a file of numbers of type int and outputs all of those numbers to another file, but without any duplicate numbers. You should assume that the input file is sorted from smallest to largest with one number on each line. After the program is run, the output file should contain all numbers that are in the original file, but no number should appear more than once. The numbers in the output file should...
Write a program in Easy68K: a) Define an array of numbers in the memory.
Write a program in Easy68K: a) Define an array of numbers in the memory. b) Read two numbers from keyboard. The first number is the size of the array and the second number is what index of the array you want to access. The index you entered can be larger than the array. c) Display the element indexed by (index % size) in the array. 
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT