Computer Science, asked by Akshaya23, 1 year ago

print sum of two input numbers without using arithmetic operator


AnviGottlieb: we don't have to use arithmetic operator in printing statement .. or during execution?
AnviGottlieb: please specify
Akshaya23: Java program we use that
AnviGottlieb: So u dont want a Java program?
Akshaya23: I want but without using arithmetic operations how it is possible but it is my task
AnviGottlieb: I can suggest you one thing ^^
AnviGottlieb: http://googleweblight.com/i?u=http://javarevisited.blogspot.com/2013/06/how-to-add-two-integer-numbers-without-plus-arithmetic-operator-java-example.html?m%3D1&grqid=OvYWavSF&hl=en-IN
AnviGottlieb: See this site b
Akshaya23: Thanks

Answers

Answered by AnviGottlieb
0
Heya!
Here's your answer!
___________
___

Suppose we have two Numbers - 50 and 100.
So without using any arithmetic operators, here's how we add it using add() function .

Program:-
public class addnumber
{

public static void main(String ar[])
{

System.out.println(" Sum of 50 and 100 is : " + add(50, 100));
}

Therefore,
OUTPUT:-
Sum of 50 and 100 is : 150

_______
___

Hope that this helps you^^

Akshaya23: Thanks my friend
AnviGottlieb: welcome ^^
AnviGottlieb: i hope the Answer is ok and understandable
Akshaya23: Yeah it is really good to understand
Answered by Anonymous
0
Hi friend,

Your answer:


import java.util.Scanner;

public class sp1

{

static int add(int x, int y)

int carry;

while(y != 0)

{

int carry = x & y;

x = x ^ y;

y = carry << 1;



return x;

}


public static void main(String args[])


{


Scanner sc = new Scanner(System.in);


System.out.println("Enter the numbers:");


int x = sc.nextInt();


int y = sc.nextInt();


System.out.println("The Summation is: "+add(x, y));


input.close();

}

}


Hope it helps!
Similar questions