Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


can we add two numbers without using arthematic operators?
if possible how?

Answers were Sorted based on User's Feedback



can we add two numbers without using arthematic operators? if possible how?..

Answer / mohan

public static int addIterative(int a, int b){
while (b != 0){
int carry = (a & b) ; //CARRY is AND of two bits

a = a ^b; //SUM of two bits is A XOR B

b = carry << 1; //shifts carry to 1 bit to calculate sum
}
return a;
}

Is This Answer Correct ?    0 Yes 0 No

can we add two numbers without using arthematic operators? if possible how?..

Answer / sravanthi

Yes we can 2 numbers without using arthematic operator.
We can use logical operators instead of arthematic operator.
The ex program is
class A
{
public static void main(String a[])
{
byte a=5;
byte b=6;
int c;
c=a||b;
System.out.println(c);
}
}

Is This Answer Correct ?    4 Yes 5 No

can we add two numbers without using arthematic operators? if possible how?..

Answer / g ch vishnu vardhan reddy

we can add two no's by using shift operator.

Is This Answer Correct ?    2 Yes 4 No

can we add two numbers without using arthematic operators? if possible how?..

Answer / anandhakrishnan

import java.io.*;
class add
{
public static void main(String args[])
{
int a = 6;
int b = 3;
System.out.println("sum of a and b is :: "+(a|b));
}
}

Is This Answer Correct ?    0 Yes 2 No

can we add two numbers without using arthematic operators? if possible how?..

Answer / satya

Hi we can add two number with out using arithemaic
operators.


just give


int a = 10;
int b = 5;
System.out.println("sum of a and b is :: "+(a|b))

Is This Answer Correct ?    10 Yes 21 No

Post New Answer

More Core Java Interview Questions

What do you mean by jjs in java8?

0 Answers  


if am have 100 threads(for ex:T1,T2---T100) how we give priority to these threads and how the system excute these threads

2 Answers  


Can we sort array in java?

0 Answers  


Is 0 true or is 1 true?

0 Answers  


What is data member in java?

0 Answers  


What happens when the main() isn't declared as static?

1 Answers  


What is complexity in java?

0 Answers  


what is collatration?

0 Answers  


Does google use java?

0 Answers  


Can It is possible to synchronize the constructor of a Java Class?

0 Answers  


What is threaded programming and when is it used? : Java thread

0 Answers  


How to send a request to garbage collector?

4 Answers  


Categories