Computer Science, asked by NirnoyCuber, 11 months ago


Write a program to input three integers and find their sum, without using the mathematical operator plus in java

Answers

Answered by ruchi5794
10

Answer:

import java.util.Scanner;

public class Example111 {

public static void main(String[] arg)

{

int x, y ;

Scanner in = new Scanner(System.in);

System.out.print("Input first number: ");

x = in.nextInt();

System.out.print("Input second number: ");

y = in.nextInt();

while(y != 0){

int carry = x & y;

x = x ^ y;

y = carry << 1;

}

System.out.print("Sum: "+x);

System.out.print("\n");

}

}

Answered by coolvd
1

Answer:

import java.util.Scanner;

public class Example111 {

public static void main(String[] arg)

{

int x, y ;

Scanner in = new Scanner(System.in);

System.out.print("Input first number: ");

x = in.nextInt();

System.out.print("Input second number: ");

y = in.nextInt();

while(y != 0){

int carry = x & y;

x = x ^ y;

y = carry << 1;

}

System.out.print("Sum: "+x);

System.out.print("\n");

}

}

Explanation:

Similar questions