Data Types
Notes, Hacks, and HW for Data Types.
public class BinaryAdd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first binary number: ");
// Use a radix of 2 cuz input is binary
String input1 = sc.nextLine();
int a = Integer.parseInt(input1, 2);
System.out.println(input1);
System.out.print("Enter second binary number: ");
String input2 = sc.nextLine();
int b = Integer.parseInt(input2, 2);
System.out.println(input2);
int sum = a + b;
System.out.println("Sum of two binary numbers is: " + Integer.toBinaryString(sum));
}
}
BinaryAdd.main(null);
import java.lang.Math;
int a = (int)(Math.random()*100);
System.out.println(a);
int b = (int)(Math.random()*100);
System.out.println(b);