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...
Write a java program creating an array of the numbers 1 through 10. Shuffle those numbers....
Write a java program creating an array of the numbers 1 through 10. Shuffle those numbers. Randomly pick a number between one and ten and then sequentially search the array for that number. Once the number is found, place that number at the top of the list. Print the list. Perform #3 thru #5 ten times.
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.
To understand the value of counting loops: Write a java program that implements matrix multiplication using...
To understand the value of counting loops: Write a java program that implements matrix multiplication using counting loop constructs. Then write the same program using only logical loops—for example, while loops. Write 2 classes for each program Sample Result is shown below: Enter the number of rows of matrix A: 2 Enter the number of columns of matrix A: 3 Enter the number of columns of matrix B: 3 Enter the number of columns of matrix B: 4 Enter matrix...
To understand the value of counting loops: Write a java program that implements matrix multiplication using...
To understand the value of counting loops: Write a java program that implements matrix multiplication using counting loop constructs. Then write the same program using only logical loops—for example, while loops. Sample Result is shown below: Enter the number of rows of matrix A: 2 Enter the number of columns of matrix A: 3 Enter the number of columns of matrix B: 3 Enter the number of columns of matrix B: 4 Enter matrix A; 1 2 3 4 5...
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...
use java Write a program that, given two binary numbers represented as strings, prints their sum...
use java Write a program that, given two binary numbers represented as strings, prints their sum in binary. The binary strings are comma separated, two per line. The final answer should not have any leading zeroes. In case the answer is zero, just print one zero i.e. 0 Input: Your program should read lines from standard input. Each line contains two binary strings, separated by a comma and no spaces. Output: For each pair of binary numbers print to standard...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT