What is wrong in the code?

import java.util.*;
public class Main {
public static void main(String args[]) {

	int num = n;
    int dec_value += 0;

    
    int base = 1;

    int temp = num;
    while (temp > 0) {
        int last_digit = temp % 10;
        temp = temp / 10;

        dec_value += last_digit * base;

        base = base * 2;
    }

    return dec_value;
}


public static void main(String[] args)
{
    int num = 10101001;
    System.out.println(binaryToDecimal(num));
}

}

@kasturichakraborty36_24075fa79f00d4e8 Sorry for the late reply. The problems with your code is :
i) When you have initialized dec_value it should be initialized like this :
int dec_value = 0;
not like this
int dec_value += 0;
ii) Take input from user dont hard code the value of int num in main function.
iii)Major problem : The code you have sent contains two main functions which is not allowed so change the upper main funtion to binaryToDecimal and change its return type to int.
Corrected code is below :

import java.util.*;
public class Main {
public static int binaryToDecimal(int n) {

	int num = n;
    int dec_value = 0;

    
    int base = 1;

    int temp = num;
    while (temp > 0) {
        int last_digit = temp % 10;
        temp = temp / 10;

        dec_value += last_digit * base;

        base = base * 2;
    }

    return dec_value;
}


public static void main(String[] args)
{
	Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    System.out.println(binaryToDecimal(num));
}
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.