Well, you can use while loop, like this,
import java.util.Scanner;
public class DecimalToBinaryExample
{
public static void main(String[] args)
{
int num;
int a = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter a decimal number : ");
num = sc.nextInt();
int binary[] = new int[100];
while(num != 0)
{
binary[a] = num % 2;
num = num / 2;
a++;
}
System.out.println("The binary value is : ");
for(int b = a - 1; b >= 0; b--)
{
System.out.println("" + binary[b]);
}
sc.close();
}
}
You can refer example below for some good explanation,
convert decimal to binary example.