Sunday, March 29, 2009

Puzzle 10 – Solution

The key here is that ‘division is the reverse of multiplication.’

It is pretty easy to multiple two integers using repeated addition. However it’s a bit difficult to extend the same logic for floating point numbers. The easiest way to perform multiplication without using the ‘*’ sign is to do a division.

package com.twister;
public class Multiply{
public static void main(String args[]){
float num1 = 20.5f;
float num2 = 2.0f;
float product = num1/(1.0f/num2);
System.out.println(
"The product of the Numbers is : "+product);
}
}

Sorry no correct answers this week!

1 comment:

  1. as i guess it is 41.0

    i run your code if there is any twist again it is 41.0


    nsureshreddy@live.com

    ReplyDelete

Solution for this question?