Extra Seed Post
Extra seed blog post for AP CSA
import java.util.Scanner;
import java.util.ArrayList;
public class seedExtra {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
int a = userInput.nextInt();
int b = userInput.nextInt();
int c = a + b;
ArrayList<Integer> binary = new ArrayList<Integer>();
int sum = 0;
for (int i = 7; i >= 0; i--) {
sum += Math.pow(2, i);
if (sum == c) {
binary.add(1);
for (int j = i - 1; j >= 0; j--) {
binary.add(0);
}
break;
} else if (sum > c) {
sum -= Math.pow(2, i);
binary.add(0);
} else if (sum < c) {
binary.add(1);
}
}
String finalAnswer = "";
int zeroCount = 0;
for (int x = 0; x < binary.size(); x++) {
finalAnswer += binary.get(x);
}
for (int y = 0; y < finalAnswer.length(); y++) {
if (finalAnswer.charAt(y) == '1') {
finalAnswer = finalAnswer.substring(y, finalAnswer.length());
break;
} else if (y == finalAnswer.length() - 1) {
finalAnswer = "0";
break;
}
}
System.out.println(finalAnswer);
}
}
seedExtra.main(null);