首页 > 代码库 > 解题.for; block scope; while; "2 to the " + i + " power is " + result
解题.for; block scope; while; "2 to the " + i + " power is " + result
1 package com.java7; 2 3 public class WhileDemo { 4 public static void main(String[] args) { 5 int e; 6 int result; 7 for(int i = 0; i < 10; i++){ 8 result = 1; 9 e = i;10 while(e > 0){11 result *= 2;12 e--;13 }14 15 System.out.println("2 to the " + i + " power is " + result);16 }17 }18 }
执行过程:
1: i = 0; result = 1; e = 0;
2: i = 1; result = 1; e = 1; result = result(1)*2 = 2; e = 0; end loop;
3: i = 2; result = 1; e = 2; result = result(1)*2 = 2; e = 1; result = result(2)*2 = 4; e = 0; end loop;
4: // ...
解题.for; block scope; while; "2 to the " + i + " power is " + result
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。