This post has been edited by harishn: 16 December 2007 - 10:55 AM
any one find a solution for this (addition of two numbers without usincan any one write a java rogram for adding two numbers without using o
15 Replies - 2644 Views - Last Post: 08 March 2010 - 04:23 AM
#1
any one find a solution for this (addition of two numbers without usin
Posted 16 December 2007 - 09:45 AM
Replies To: any one find a solution for this (addition of two numbers without usin
#2
Re: any one find a solution for this (addition of two numbers without usin
Posted 16 December 2007 - 10:04 AM
#3
Re: any one find a solution for this (addition of two numbers without usin
Posted 16 December 2007 - 04:20 PM
harishn, on 16 Dec, 2007 - 09:45 AM, said:
I am thinking that can't be done without at least an assignment operator '=' at some point. What are the exact restrictions on which operators you can and cannot use? Can you simply relocate the addition operator to a method and just call that add method instead?
#4
Re: any one find a solution for this (addition of two numbers without usin
Posted 17 December 2007 - 03:31 AM
#5
Re: any one find a solution for this (addition of two numbers without usin
Posted 17 December 2007 - 12:33 PM
#6
Re: any one find a solution for this (addition of two numbers without usin
Posted 17 December 2007 - 01:04 PM
This post has been edited by Programmist: 17 December 2007 - 01:11 PM
#7
Re: any one find a solution for this (addition of two numbers without usin
Posted 17 December 2007 - 11:00 PM
harishn, on 17 Dec, 2007 - 12:33 PM, said:
Try something along these lines, create a method which takes two int params. Then create two Object arrays (need to use assignment operator unless you make a method which will return a new array) which are the sizes of each param. Then do a for each loop (no operators involved there) over both arrays where you add the elements in the array to list. Then return the size of the list. You'll only need assignment doing it that way. If you go so far as to extend a List class and in the for loops add objects to your implicit list, then you can get away without using any operators (not even assignment).
#8
Re: any one find a solution for this (addition of two numbers without usin
Posted 18 December 2007 - 04:16 AM
#9
Re: any one find a solution for this (addition of two numbers without usin
Posted 18 December 2007 - 06:40 AM
ericode, on 18 Dec, 2007 - 12:00 AM, said:
harishn, on 17 Dec, 2007 - 12:33 PM, said:
Try something along these lines, create a method which takes two int params. Then create two Object arrays (need to use assignment operator unless you make a method which will return a new array) which are the sizes of each param. Then do a for each loop (no operators involved there) over both arrays where you add the elements in the array to list. Then return the size of the list. You'll only need assignment doing it that way. If you go so far as to extend a List class and in the for loops add objects to your implicit list, then you can get away without using any operators (not even assignment).
definitely a clever use of iteration and less complex that implementing a boolean bit adder (although maybe not as interesting
#10
Re: any one find a solution for this (addition of two numbers without usin
Posted 18 December 2007 - 07:08 AM
harishn, on 17 Dec, 2007 - 02:33 PM, said:
You must be very, very specific as to what counts as an opertator. Here a list from java: http://java.sun.com/.../opsummary.html
If it's only "arithmetic operators" that are out, the here's an answer.
int a=8; int b=9; int c=a; for(int i=0; i<b; i++, c++);
#11
Re: any one find a solution for this (addition of two numbers without usin
Posted 02 January 2009 - 05:26 AM
#12
Re: any one find a solution for this (addition of two numbers without usin
Posted 02 January 2009 - 06:20 AM
#13
Re: any one find a solution for this (addition of two numbers without usin
Posted 02 January 2009 - 10:32 AM
You can add two numbers using bit-operations AND and XOR (both twice) in combination. It's quite simple but I won't show you as this is clearly homework and you haven't shown any effort to solve it.
#14 Guest_dasdsa*
Re: any one find a solution for this (addition of two numbers without usin
Posted 08 March 2010 - 12:21 AM
if (b == 0) return a;
int sum = a ^ b; // add without carrying
int carry = (a &
return add_no_arithm(sum, carry); // recurse
}
#15
Re: any one find a solution for this (addition of two numbers without usin
Posted 08 March 2010 - 12:42 AM
|
|

New Topic/Question
This topic is locked





MultiQuote










|