Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:51:27+00:00 2026-05-26T14:51:27+00:00

I tried Binary multiplication technique on decimal numbers. Algorithm: To multiply two decimal numbers

  • 0

I tried Binary multiplication technique on decimal numbers.

Algorithm:

To multiply two decimal numbers x and y, write them next to each
other, as in the example below. Then repeat the following: divide the first number by 2,
rounding down the result (that is, dropping the :5 if the number was odd), and double the
second number. Keep going till the first number gets down to 1. Then strike out all the rows
in which the first number is even, and add up whatever remains in the second column.

11 13

5 26

2 52

1 104

……..

143 (answer)

Code:

class Multiply
{
static int temp;
static int sum;

public static void main(String[] args)
{
    int x = Integer.parseInt(args[0]);
    int y = Integer.parseInt(args[1]);
    int ans = multiply(x , y);
    System.out.println(ans);
}
public static int multiply(int x, int y)
{
    if(x==1)
    {
        System.out.println(x+" : "+y);
        return y;
    }


    temp = multiply(x/2, y*2);

    if(x%2==0)
    {
        System.out.println(x+" : "+y);
        return temp;
    }
    else
    {
        System.out.println(x+" : "+y);
        sum = sum+temp;
        return sum;
    }
}
}

Something is wrong with the recursion i think but i couldn’t find what it is!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:51:28+00:00Added an answer on May 26, 2026 at 2:51 pm

    Your recursion should be like this –

    public class Multiply {
        static int temp = 0;
        static int sum = 0;
    
        public static void main(String[] args) {
            int x = Integer.parseInt("11");
            int y = Integer.parseInt("9");
            int ans = multiply(x, y);
            System.out.println(ans);
        }
    
        public static int multiply(int x, int y) {
            if (x == 1) {
                System.out.println(x + " : " + y);
                return sum + y;
            }
            if (x % 2 == 0) {
                System.out.println(x + " : " + y);
            } else {
                System.out.println(x + " : " + y);
                sum = sum + y;
            }
            return multiply(x / 2, y * 2);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to implement binary insertion sort algorithm. Here is my code: public
Basically, for revision purposes tried to code a Binary Search algorithm in Processing. Decided
So I recently installed cabal (from the default binary of ArchLinux). I then tried
I need to work with a binary number. I tried writing: const char x
I tried asking the question php - Is there a binary package for php5-sqlite3
I tried to compile the example posted ( C++ Service Providers ) and failed
I'm reading a binary file and storing each record into a byte[] . Now
I've tried using both binary search, and while loops and for loops in my
I've tried passing binary SQLite DBs over the network between different OSes and architectures
I've tried to understand what sorted trees are and binary trees and avl and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.