Skip to content

Instantly share code, notes, and snippets.

@mevlanaayas
Created July 28, 2018 07:57
Show Gist options
  • Save mevlanaayas/94e26b030f86eba4e6aac6781ff1bfb1 to your computer and use it in GitHub Desktop.
Save mevlanaayas/94e26b030f86eba4e6aac6781ff1bfb1 to your computer and use it in GitHub Desktop.
Implementig integer add operation with ArrayList without any usages of arithmetic operations
import java.util.ArrayList;
import java.util.Scanner;
public class AddWithoutArithmeticOperator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int numberOne = scanner.nextInt();
int numberTwo = scanner.nextInt();
int[] firstIntArray = new int[numberOne];
int[] secondIntArray = new int[numberTwo];
System.out.println(merge(firstIntArray, secondIntArray));
}
private static int merge(int[] one, int[] two) {
ArrayList<Integer> combinedArray = new ArrayList<Integer>();
for ( int n : one) combinedArray.add(n);
for ( int n : two) combinedArray.add(n);
return combinedArray.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment