work4的code和问题

//for循环
package cn.itcast.work4;
/*
* A:循环结构的分类
* for,while,do...while
* B:循环结构for语句的格式:
*
for(初始化表达式;条件表达式;循环后的操作表达式) {
循环体;
}
* C执行流程:
* a:执行初始化语句
* b:执行判断条件语句,看其返回值是true还是false
* 如果是true,就继续执行
* 如果是false,就结束循环
* c:执行循环体语句;
* d:执行循环后的操作表达式
* e:回到B继续。
* D:案例演示
* 在控制台输出10次"helloworld"
*/
class For {
public static void main(String[] args) {
//在控制输出10次helloworld,这样做不推荐,因为复用性太差
/*System.out.println("helloworld");
System.out.println("helloworld");
System.out.println("helloworld");
System.out.println("helloworld");
System.out.println("helloworld");
System.out.println("helloworld");
System.out.println("helloworld");
System.out.println("helloworld");
System.out.println("helloworld");
System.out.println("helloworld");*/

for (int i = 1;i <= 10 ;i++ ) {
System.out.println("helloworld");
}
}
}

运行结果:

//while循环
package cn.itcast.work4;
/*
* A:循环结构while语句的格式:
*
while循环的基本格式:
while(判断条件语句) {
循环体语句;
}

完整格式:

初始化语句;
while(判断条件语句) {
循环体语句;
控制条件语句;
}
* B:执行流程:
* a:执行初始化语句
* b:执行判断条件语句,看其返回值是true还是false
* 如果是true,就继续执行
* 如果是false,就结束循环
* c:执行循环体语句;
* d:执行控制条件语句
* e:回到B继续。
* C:案例演示
* 需求:请在控制台输出数据1-10
*/
class While {
public static void main(String[] args) {
int x = 1;
while (x <= 10) {
System.out.println("x = " + x);
x++;
}
}
}

运行结果:

//do_while循环
package cn.itcast.work4;
/*
* A:循环结构do...while语句的格式:
*
do {
循环体语句;
}while(判断条件语句);

完整格式;
初始化语句;
do {
循环体语句;
控制条件语句;
}while(判断条件语句);
* B:执行流程:
* a:执行初始化语句
* b:执行循环体语句;
* c:执行控制条件语句
* d:执行判断条件语句,看其返回值是true还是false
* 如果是true,就继续执行
* 如果是false,就结束循环
* e:回到b继续。
* C:案例演示
* 需求:请在控制台输出数据1-10
*/
class DoWhile {
public static void main(String[] args) {
//while 和do while的区别
/*int i = 11;
do {
System.out.println("i = " + i);
i++;
}
while (i <= 10);

System.out.println("---------------------");

int j = 11;
while (j <= 10) {
System.out.println("j = " + j);
j++;
}*/

/*for (int i = 1;i <= 10 ;i++ ) {
System.out.println("i = " + i);
}

//System.out.println("i = " + i); for语句执行后变量会被释放,不能再使用
System.out.println("-------------------");
int i = 1;
while (i <= 10) {
System.out.println("i = " + i);
i++;
}
System.out.println("-------------------");
System.out.println("i = " + i); //while语句执行后,初始化变量还可以继续使用*/

//while语句的无限循环
/*while (true) {
System.out.println("hello world");
}*/

//System.out.println("hello world");
//for语句的无限循环
for (; ; ) {
System.out.println("hello world");
}
}

}

运行结果:

//循环嵌套之九九乘法表

package cn.itcast.work4;
/*
* A:案例演示
* 需求:在控制台输出九九乘法表。

1 * 1 = 1
1 * 2 = 2 2 * 2 = 4
1 * 3 = 3 2 * 3 = 6 3 * 3 = 9
...

*
**
***
*/
class For_99 {
public static void main(String[] args) {
for (int i = 1;i <= 9 ;i++ ) { //行数
for (int j = 1;j <= i ;j++ ) { //列数
System.out.print(j + "*" + i + "=" + (i * j) + "\t" );
}
System.out.println();
}

//System.out.println("\""); 转义双引号
//System.out.println(‘\‘‘); //转义单引号
}
}

运行结果:

时间: 2024-07-30 08:37:32

work4的code和问题的相关文章

从微信官方获取微信公众号名片:http://open.weixin.qq.com/qr/code/?username=haihongruanjian

从微信官方获取微信公众号名片:http://open.weixin.qq.com/qr/code/?username=haihongruanjian 个人的号,不知道怎么获取.

微信 {&quot;errcode&quot;:40029,&quot;errmsg&quot;:&quot;invalid code, hints: [ req_id: Cf.y.a0389s108 ]&quot;}

{"errcode":40029,"errmsg":"invalid code, hints: [ req_id: Cf.y.a0389s108 ]"} 问题:微信网页授权后,获取到 openid 了,一刷新又没了 微信网页授权获取到的 code 只能使用一次(5分钟内有效),使用一次后,马上失效. 页面授权跳转成功,根据 code 也换取到 openid 了. 此时刷新页面,并不会再次进行授权,而是直接刷新了一下上一次授权跳转后的链接,带的还是

在linux系统中安装VSCode(Visual Studio Code)

1.从官网下载压缩包(话说下载下来解压就直接可以运行了咧,都不需要make) 访问Visual Studio Code官网 https://code.visualstudio.com/docs?dv=linux64 我是64位的: wget https://az764295.vo.msecnd.net/stable/7ba55c5860b152d999dda59393ca3ebeb1b5c85f/code-stable-code_1.7.2-1479766213_amd64.tar.gz 2.解

set up trace code tool

這以 GNU GLOBAL 6.5.6 為示範 1: install GNU GLOBAL https://www.gnu.org/software/global/download.html sudo ./configure; 若有以下 error,請看更下方的 Q5 說明. configure: checking "location of ncurses.h file"... configure: error: curses library is required but not f

Ubuntu16.04下安装VS Code

在Ubuntu下面安装Visual Studio Code sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make sudo apt-get update sudo apt-get install ubuntu-make umake web visual-studio-code 终于又看见亲切的大麻花了

CSDN code使用教程之git用法详解

首先需要下载GIT客户端,http://git-scm.com/downloads...   然后再code.csdn.net上面创建一个项目,如果 你的项目已经存在,那么请建立项目的时候不要选择自动生成readme文件.填写项目名称,去掉下面的勾勾,然后点击创建就OK了. 下面的就是配置本地客户端了,确认你在CSDN id,获取的方式是在登录后,进入passport.csdn.net,在"个人帐号"的最下端查看用户名:也就是你的昵称,我的就是Linux_Google 然后在命令行中输

.NET跨平台之mac 下vs code 多层架构编程

合肥程序员群:49313181.    合肥实名程序员群:128131462 (不愿透露姓名和信息者勿加入,申请备注填写姓名+技术+工作年限) Q  Q:408365330     E-Mail:[email protected] 概述: 为了研究跨平台.NET 开发,我打算利用.NET core 编写一个跨平台的cms,这个CMS我也秉着开源的原则放到github上面,为.NET 开源社区做点小小的贡献吧.如果有兴趣的可以联系我一起为.NET开源和跨平台做点小小的贡献吧.EgojitCMS传送

安装GO语言环境之安装Visual Studio Code插件

在安装Visual Studio Code插件的时候,由于谷歌的限制,在下载下列插件的时候会报错: go get -u -v github.com/nsf/gocode go get -u -v github.com/rogpeppe/godef go get -u -v github.com/golang/lint/golint go get -u -v github.com/lukehoban/go-find-references go get -u -v github.com/lukeho

Code First添加一个现有数据库中的表

描述 刚刚使用EF,还没搞明白,遇到下面问题,记录一下. 都说EF好用,一直也没用过,以前写代码都是ADO.NET,写起来费时费力还没什么大进展,如果能把这些事简化一下把精力放到逻辑或者更有用的地方岂不是更好.所以想使用EF.Code First,从字面的意思来看是先有代码后有数据库,通过Model来创建数据库,好像只能是通过Model来生成数据库,至少我接触2天以来是这样,项目已经开始一段时间了,数据库已经有一定的数据,虽然是测试数据,但也不想删掉,从新添加数据也是很烦人的事.想找到一种能够不