专题文章
时长:00:00更新时间:2024-12-04 03:46:03
public class Test1 {。public static void main(String[] args) throws Exception {。int a = 1。int n = 3。for (int i = 0;i <;n;i++) {。a = a * 2。};System.out.println(a)。};};在这个示例中,首先将变量a初始化为1,然后通过一个for循环将2重复相乘n次。每次循环中,我们将a乘以2,这样a的值就相当于2的当前循环次数。当循环结束后,a的值就是2的n次方。最后,我们使用System.out.println()输出结果。
查看详情