- import java.util.Scanner;
- public class BinaryMultiply
- {
- public static void main (String args[])
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Hello, i multiply binary numbers!" + "rn" + "Please enter the first four digit binary number:");
- int number1 = scan.nextInt();
- System.out.println("Please enter the second four digit number:");
- int number2 = scan.nextInt();
- mBinary(number1,number2);
- }
- public static int[] mBinary(int num1, int num2)
- {
- int [] bArray2 = new int[4]; // int array with 4 elements.
- int [] bArray = new int[4]; // int array with 4 elements.
- while(num1>0)
- {
- int digit = num1%10;
- for(int i=0;i<4;i++)
- {
- bArray[i]= digit;
- }
- // System.out.println("the first number in the array is:" + bArray[0]);
- num1/=10;
- }
- while(num2>0)
- {
- int digit2 = num2%10;
- for(int i=0;i<4;i++)
- {
- bArray2[i]= digit2;
- }
- // System.out.println("the first number in the array is:" + bArray2[0]);
- num2/=10;
- }
- int bAnswer[] = new int[bArray.length];
- for(int i=0;i<bArray.length;i++)
- {
- bAnswer[i]+= bArray2[i]*bArray[i];
- System.out.print(" "+bAnswer[i]);
- }
- return (bAnswer);
- }
- }
Binarymultiply
By: microhaxo | Date: Jun 6 2009 22:56 | Format: None | Expires: never | Size: 1.23 KB | Hits: 863
Latest pastes
18 hours ago
1 days ago
1 days ago
1 days ago
2 days ago