+ 1

pls tell me what is the problem in the code ?

import java.util.Scanner; class addbin { public static void main(String args[]) { int num1,num2; int digi1,digi2,sum=0,carry=0,j; int[] arr=new int[20]; Scanner sc=new Scanner(System.in); System.out.print("Enter 1st binary numebr:"); num1=sc.nextInt(); System.out.print("Enter 2nd binary numebr:"); num2=sc.nextInt(); //logic part----------------------------- for(j=arr.length-1;j>=0;j--);{ digi1=num1%10; digi2=num2%10; num1=num1/10; num2=num2/10; sum=digi1+digi2+carry; //conditional logic---------------------- if(sum==0){ arr[j]=0; carry=0; } else if(sum==1){ arr[j]=1; carry=0; } else if(sum==2){ arr[j]=0; carry=1; } else if(sum==3){ arr[j]=1; carry=1; } } for( j=0;j<arr.length;j++) { System.out.print(arr[j]); } } }

14th Jan 2023, 9:15 AM
Rishu Dubey
Rishu Dubey - avatar
5 Answers
+ 2
line:15 for(j=arr.length-1;j>=0;j--)/;👈 remove this srmicolon here, it ends loop here..{
14th Jan 2023, 9:34 AM
Jayakrishna 🇼🇳
+ 1
Instead can you tell, what is the problem you are facing..? What is task you are trying by this code? Save code and share link for easy debug...
14th Jan 2023, 9:22 AM
Jayakrishna 🇼🇳
14th Jan 2023, 9:28 AM
Rishu Dubey
Rishu Dubey - avatar
+ 1
Ok thanks I didn't notice cause of bracket
14th Jan 2023, 9:36 AM
Rishu Dubey
Rishu Dubey - avatar
0
Try running it
14th Jan 2023, 9:29 AM
Rishu Dubey
Rishu Dubey - avatar