System.out.println("This is the ancestry calculator. Enter number of generations: ");
Scanner input = new Scanner(System.in);
int generations = input.nextInt();
int ancestors;
ancestors = Math.pow (2, generations);
当我不尝试将任何内容从双精度转换为...时,我在最后一行收到错误“可能从双精度转换为整数”(错误指针指向数字“ 2”)。
Math.pow()方法返回一个双精度值,因此,如果需要将其分配给祖先,则需要对其进行强制转换。
ancestors =(int) Math.pow (2, generations);
使用以下任何一种: