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?
Answers
Answered by
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^^
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^^
Answered by
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!
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