Compilation error

import java.util.;
import java.io.
;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int b = scn.nextInt();
int ans = 0;

    int power = 1;
    while(n>0){
        int dig = n%b;
        n = n/b;
        ans += dig * power;
        power = power * 10;

    }
    System.out.println(ans);
}

}

my this code is showing error in cb compiler but it’s working fine on vs code… please tell what’s wrong???

public static int decimalToOctal(int n, int b){ int ans = 0; int power = 1; while(n>0){ int dig = n%b; n = n/b; ans += dig * power; power = power * 10; } return ans; } i tried writing this function but still it didnt work

Hey @shruti_codess28,
You have an error in this line.

If we pay attention to the input format we can observe that the program expects just one input, but you provided 2 inputs. The scanner couldnt read the next input thus we got a compilation error.

To resolve this, we can simply make this change in the code:

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.