Your code seems to be copied (incorrectly) from somewhere as basic concepts, such as
- only one function can exists with the same signature (the function sum was duplicated)
- opening braces/parenthesis must be closes
are violated.
If you're new to programming, please, review some tutorials to familiarize yourself with the language basics.
I fixed these issues, tested the program: it runs, it worked for a random input (100 + 10 = 110), but I didn't go into details.
Here's the fixed code:
import java.util.Scanner;
public class Main
{
private String firstNum;
private String secondNum;
private String sum;
public static void main(String[ ] args)
{
Main lab = new Main();
lab.input(); // Read two binary numbers
lab.output( ); // Display output
}
public void input()
{
Scanner reader = new Scanner(System.in);
System.out.print("Enter the first binary number: ");
firstNum = reader.next();
System.out.print("Enter the second binary number: ");
secondNum = reader.next();
}
public static String sum(String n1, String n2)
{
int a = Integer.parseInt(n1, 2);
int b = Integer.parseInt(n2, 2);
return Integer.toBinaryString(a + b);
}
public void output()
{
System.out.println(firstNum + " + " + secondNum + " = " + sum(firstNum, secondNum));
}
}