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?

0 votes
asked 3 days ago 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));



2 Answers

–1 vote
answered 3 days ago by 256 SUJITH KUMAR (120 points)
int main()
    int a[1000],i,n,smallest,largest;
    printf("enter the size of the array:");
    printf("enter elements in array:");
   printf("largest of the array is:%d",largest);
   printf("smallest of the array is:%d",smallest);
    return 0;
commented 2 days ago by Peter Minarik (22,320 points)
I'm not sure why you posted this.

The original poster asked a Java question. Your code is C. Your code does something totally different, not even solving the same problem.

I won't go into various formatting and user experience issues, but I'd like to point out an important problem with your code: you assume the user won't enter a size that's larger than 1000. If they do, memory corruption will happen.
0 votes
answered 3 days ago by Peter Minarik (22,320 points)
commented 2 days ago 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.