您的位置:首页 > 编程语言 > Java开发

Java基础(极客)——06、Java循环结构语句的特点和使用方法

2015-05-26 15:01 876 查看
/**

* 2、用while循环打印所有大写英文字母和对应的Unicode码解法(1)

*

【示例】用while循环打印所有大写英文字母和对应的unicode码

解法(1)

*/

public class XunHuanDemo1 {

public static void main(String[] args) {

int i = 65;//65对应的unicode嗎是A

while (i <= 65 + 25) {

System.out.println((char) i + ":" + i);

i++;

}

}

}//class

/**

* 3、用while循环打印所有大写英文字母和对应的Unicode码解法(2)

【示例】用while循环打印所有大写英文字母和对应的unicode码

解法(2)

*/

public class XunHuanDemo2 {

public static void main(String[] args) {

//在java中char底层室友int类型来处理的

char c = 'A';

while (c <= 'Z') {

System.out.println(c + ":" + (int) c);

c++;

}

}

}//class

/**

* 4、Do While循环使用格式和执行流程

do...while

do {

// 循环内容

} while (循环继续的条件表达式);

*/

public class XunHuanDemo3 {

public static void main(String[] args) {

int i = 97;

do {

System.out.println((char) i + ":" + i);

i++;

} while (i <= 97 + 25);

}

}//class

/**

* 5、用Java do while循环打印所有大写英文字母和对应的Unicode码解法(1)

* 6、用java do while循环打印所有大写英文字母和对应的Unicode码解法(2)

do...while

*/

public class XunHuanDemo4 {

public static void main(String[] args) {

char c = 'a';

do {

System.out.println(c + ":" + (int) c);

c++;

} while (c <= 'z');

}

}//class

/**

*7、Java For循环语句的格式

for循环

*/

public class XunHuanDemo5 {

public static void main(String[] args) {

/*执行顺序

* 先执行i=1;

* 判断i <= 20;

* 执行大括号中的打印

* i++;

*

* 判断i <= 20;

* 执行大括号中的打印

* i++;

*

*

* ***/

for (int i = 1; i <= 20; i++) {

System.out.println("做俯卧撑的次数:" + i);

}

}

}//class

源码下载:
http://download.csdn.net/detail/zhaihaohao1/8741715
视频下载:
http://c38.yunpan.360.cn/my/index/#%2F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%2Fjava%2F
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: