Solve My Question Pls....

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2008
Posts: 4
Reputation: thariqrasheed is an unknown quantity at this point 
Solved Threads: 0
thariqrasheed's Avatar
thariqrasheed thariqrasheed is offline Offline
Newbie Poster

Solve My Question Pls....

 
0
  #1
Nov 29th, 2008
Hi,
Can u add numbers without using arithmetic operators in java.We can add using bitwise operators.But i m not able to get the ans.

Solve:

a+b=c;
Prove 2+2=4 without using arithmetic opreations.

Looking for u r answers
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 52
Featured Poster
jasimp's Avatar
jasimp jasimp is offline Offline
Senior Poster

Re: Solve My Question Pls....

 
0
  #2
Nov 29th, 2008
What have you done on this problem? Show us some effort and maybe you will receive help. Also, try google.
Last edited by jasimp; Nov 29th, 2008 at 10:20 am.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 4
Reputation: thariqrasheed is an unknown quantity at this point 
Solved Threads: 0
thariqrasheed's Avatar
thariqrasheed thariqrasheed is offline Offline
Newbie Poster

Re: Solve My Question Pls....

 
0
  #3
Nov 29th, 2008
I want to add two numbers for example say 2+3=5 without the arithmetic operator '+'.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 52
Featured Poster
jasimp's Avatar
jasimp jasimp is offline Offline
Senior Poster

Re: Solve My Question Pls....

 
1
  #4
Nov 29th, 2008
And I want a billion dollars
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,677
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 226
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Solve My Question Pls....

 
0
  #5
Nov 29th, 2008
One way that came to mind is use 2 for-loops
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,205
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 486
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Solve My Question Pls....

 
0
  #6
Nov 29th, 2008
What about binary calculations
010
AND
010
is
100
Last edited by peter_budo; Nov 29th, 2008 at 7:54 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Solve My Question Pls....

 
0
  #7
Nov 29th, 2008
We can multiply/divide by 2 succesive using bitwise operators .
        byte a = 4;
        byte b = (byte) (a >> 1);
        byte c = (byte) (a >> 2);
        byte d = (byte) (a << 1);

        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
May be You are looking to The Vedas (Sanskrit वेद, véda, "knowledge") arithmetic .The product of the sum - Gunitasamuchyah.
(or Trachtenbergs system to speed multiply in memory).
quuba
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 4
Reputation: thariqrasheed is an unknown quantity at this point 
Solved Threads: 0
thariqrasheed's Avatar
thariqrasheed thariqrasheed is offline Offline
Newbie Poster

Re: Solve My Question Pls....

 
0
  #8
Nov 30th, 2008
I m still can't get the answer from u guys.....

Let me explain more in detail:

class add{
public static void main(String args[])
{
int a=2,b=2,c;
c=a+b;
System.out.println("C="+c);
}
}

This what we normally done using arith operator '+'.
I want the answer c=4 without using '+' or any arith operator.
Pls suggest ur ideas through the example.. i m a beginner in java so i can clearly understand... Hoping for u r answers......
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: Solve My Question Pls....

 
0
  #9
Nov 30th, 2008
c=a+b; - here is arithmetic operator .

System.out.println("C="+c); - here is overloaded operator + .
Here this mean CONCATENATION of two String-s.
You can asked: c is not a String type. Yes it is true, but c is casting to String automatically before join.
In Your case You can write:
System.out.print("C=");
System.out.println(""+c);// "" (an empty String) can cast integer to String
How to eliminate sign + :
System.out.print("C=");
System.out.println(c);// "" automatic cast int to String

Remark: Sign + in arithmetic has two menings:
1. before a single number indicate, positive number
2. between two numbers , sum operation

Try write:
System.out.println(c++); or
System.out.println(++c); try explain difference
quuba
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,845
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 119
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC