美文网首页
JAVA 第五课

JAVA 第五课

作者: 一二三四五丶 | 来源:发表于2015-12-28 14:47 被阅读19次
  • while 循环 开始就判断

int x =10;
 while( x < 20 ) {
    System.out.print("value of x : " + x );//换行
    x++;
    System.out.print("\n");
 }
   }}```
   

* ##do while 循环    do 执行 在判断  保证至少运行一次

int x =10;
do{
System.out.print("value of x : " + x );
x++;
System.out.print("\n");//换行
}while( x < 20 );//判断```

  • 一般循环数组用for

for(int x = 10; x < 20; x = x+1) {
     System.out.print("value of x : " + x );
     System.out.print("\n"); ```
* ##break 关键字 停止整个循环的
根据你的需要

for(int x = 10; x < 20; x = x+1) {
System.out.print("value of x : " + x );
if(x == 15) {
break;
}
System.out.print("\n");```

  • continue 关键字

x=5时跳过 执行下一条循环 只对下面的语句有有影响

for(int x = 10; x < 20; x = x+1) {
     System.out.print("value of x : " + x );
  if(x==5){
    continue
}
System.out.print("\n");```
##JAVA 条件判断
  *  if 语句   如果布尔表达式的值为 true,那么代码里面的块 if 语句将被执行。如果不是 true,在 if 语句大括号后结束后的第一套代码将被执行。
嵌套if else 
* 一个 if 语句可以有0个或一个 else 语句 且它必须在 else if 语句的之后。
* 一个 if 语句 可以有0个或多个 else if 语句且它们必须在 else 语句之前。
* 一旦 else if 语句成功, 余下 else if 语句或 else 语句都不会被测试执行。

int x = 30;
if( x == 10 ){
System.out.print("Value of X is 10");
}else if( x == 20 ){
System.out.print("Value of X is 20");
}else if( x == 30 ){
System.out.print("Value of X is 30");
}else{
System.out.print("This is else statement");
} ```

  • 逻辑与(&&)

前后都成立 打印语句

  • switch 与if 功能一样 break可以在switch 中使用
  • 每种CASE后面必须有break
  • default 相当于条件语句中else
  • int char short 可以用

char grade = 'C';
switch(grade)
{
case 'A' :
System.out.println("Excellent!");
break;
case 'B' :
case 'C' :
System.out.println("Well done");
break;
case 'D' :
System.out.println("You passed");
case 'F' :
System.out.println("Better try again");
break;
default :
System.out.println("Invalid grade");
}
System.out.println("Your grade is " + grade);
}```

  • html基本结构

<h1>wozaixuexi</h1> 开头
<p> </p> 另一个段落
代码中的空格 没作用
<a href=" " ></a> 加载超链接
<img src=" "/> 加载一个图片

相关文章

网友评论

      本文标题:JAVA 第五课

      本文链接:https://www.haomeiwen.com/subject/svgbhttx.html