We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 31ab800 commit e03decfCopy full SHA for e03decf
InterviewPrograms/src/com/techgig/java/AddWithoutUsingPlus.java
@@ -0,0 +1,18 @@
1
+package com.techgig.java;
2
+
3
+import java.util.Scanner;
4
5
+public class AddWithoutUsingPlus {
6
+ public static void main(String[] args) {
7
+ Scanner scanner = new Scanner(System.in);
8
+ int a = Integer.parseInt(scanner.nextLine().trim());
9
+ int b = Integer.parseInt(scanner.nextLine().trim());
10
11
+ while (b != 0) {
12
+ int carry = a & b;
13
+ a = a ^ b;
14
+ b = carry << 1;
15
+ }
16
+ System.out.print(a);
17
18
+}
0 commit comments