Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

anyone know what i did wrong?

–3 votes
asked Apr 7, 2021 by 3 molina william (180 points) 1 flag
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 String sum(String first, String second) {

  sum(firstNum, secondNum));

  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));

}

}

1 Answer

+1 vote
answered Apr 8, 2021 by Peter Minarik (84,720 points)
commented Apr 8, 2021 by 3 molina william (180 points)
thank you so much and yes I'm new to programming
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...