Adding two numbers without using plus operator
In this example, We will show you how to write a Java program about Adding two numbers without using plus operator.
AdditionWithoutPlus.java
package com.dineshkrish; import java.util.Scanner; public class AdditionWithoutPlus { public static void main(String[] args) { AdditionWithoutPlus addition = new AdditionWithoutPlus(); Scanner scanner = new Scanner(System.in); System.out.println("Enter the first number : "); int a = scanner.nextInt(); // Reading first number System.out.println("Enter the second number : "); int b = scanner.nextInt(); // Reading second number System.out.println("Result : "+addition.add(a, b)); } public int add(int a, int b) { int c; c = (a - ~b) - 1; // Adding the two integer without using (+) return c; } }
Output
——————–
Enter the first number :
10
Enter the second number :
20
Result : 30
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet