我是java的初學者,我不明白爲什麼這不起作用。我正在嘗試編寫一個將基本10號碼轉換爲二進制的程序,但是我遇到了ArrayList問題。我不能使用ArrayList中的Add方法:ArrayList.add方法不起作用
import java.util.ArrayList;
import java.util.Scanner;
public class DecimalToBinary {
public static void main (String[] args){
Scanner reader = new Scanner (System.in);
System.out.println("This program converts a decimal number to binary.");
int decimal;
ArrayList<int[]> binary = new ArrayList<int[]>();
//Gets decimal number
System.out.print("Enter base 10 number: ");
decimal = reader.nextInt();
//Adds 1 to binary and then adds the remainders of decimal/2 after that until decimal is 1
binary.add(1, null);
while (decimal != 1){
binary.add(1, decimal%2);//This is where I get the error
decimal = decimal/2;
}//Ends While loop
}//Ends main
} //結束DecimalToBinary類