美文网首页
12月26日学习内容

12月26日学习内容

作者: 萧灬瑟 | 来源:发表于2015-12-29 10:10 被阅读0次

While循环

例子:

import java.util.Arrays;
public class Lx{public static void main(String[] args) {
    int x = 10;
    while(x < 20){
        System.out.print("volue of x : " +x);
        x++;
        System.out.print("\n");
    }
}} ```
##Do   While循环
例子:

import java.util.Arrays;
public class Lx{public static void main(String[] args) {
int x = 10;
do{
System.out.print("value of x : "+x);
x++;
System.out.print("\n");
}while(x<20);
}}```

条件判断

在Java中条件判断有两种形式:if和 switch

if 语句由一个布尔表达式后跟一个或多个语句组成。

if 语句的语法是:

if(Boolean_expression){ //Statements will execute if the Boolean expression is true}```
如果布尔表达式的值为 true,那么代码里面的块 if 语句将被执行。如果不是 true,在 if 语句大括号后结束后的第一套代码将被执行。
####例子

public class Lx{ public static void main(String args[]){
int x = 10; if(x < 20 )
{ System.out.print("This is if statement");
} } }```

if...else 语句

任何 if 语句后面可以跟一个可选的 else 语句,当布尔表达式为 false,语句被执行。

if...else 的语法是:

if(Boolean_expression){
//Executes when the Boolean expression is true}else{
//Executes when the Boolean expression is false}```
####例子

public class Lx{ public static void main(String args[]){
int x = 30;
if( x < 20){
System.out.print("This is if statement");
}else{System.out.print("This is else statement");}
} } ```

当使用 if , else if , else 语句时有几点要牢记。

一个 if 语句可以有0个或一个 else 语句 且它必须在 else if 语句的之后。
一个 if 语句 可以有0个或多个 else if 语句且它们必须在 else 语句之前。
一旦 else if 语句成功, 余下 else if 语句或 else 语句都不会被测试执行。

例子

public class Lx{ public static void main(String args[]){ 
    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");
    }
} } ```
####嵌套 if...else 语句与逻辑与(&&)
它始终是合法的嵌套 if-else 语句,这意味着你可以在另一个 if 或 else if 语句中使用一个 if 或 else if 语句。
#####例子

public class Lx{ public static void main(String args[]){
int x = 30;
int y = 10;
if ( x == 30){
if( y == 10){
System.out.print("x = 30 and y = 10");
}
}
} } ```

作业练习,建立一个数组,把元素从小到大排列

import java.util.Arrays;
public class Lx{public static void main(String[] args) {
    int [] array = {2,8,1,9,5,4};
    int temp;  for (int i = 0; i < array.length; i++)
    {   for (int j = 0; j < array.length;j++)
    {   if (array[j] > array[i])
    {   temp = array[i];
        array[i] = array[j];
        array[j] = temp; 
    }
    }
    }
    for (int i = 0; i < array.length; i++)
    {System.out.print(array[i]+" ");}
}} ```

相关文章

  • 学习内容

    语文学习d.t ,n,l ,g,k,h,j,q,x 数学学习了回答电视上的问题!还学的科学

  • 学习内容

    今天数学学了0-10书写,还学习了长方形、正方形还有球,语文学了6个单韵母和23个声母、还有整体认读

  • 学习内容

    今天数学学的一到六的合成,我学会了。语文学了几个复韵母,我学会了。回家去做作业啦!我做完啦。发一篇阅读我就睡觉啦。

  • 学习内容

    数学学习10以内的分成和合成!语文学的读一读!还有过马路儿歌

  • 学习内容

    今天上了书法课!练习了笔顺,数学还考试了!语文学习了秋天还有拼音

  • 学习内容

    语文学习了《古朗月行》,下午语文考试了!数学学的7加几,道德与法治课上老师让我们看的动画片,还发了冬季校服

  • 学习内容

    语文学了《谁会飞》《明天要远足》,数学学习了20以内的加法和连加,还有十以内的分成!上了体育课,还上了魔方课老师告...

  • 学习内容

    今天语文学习整体认读音节!声母,韵母,数学还做了一张试卷!我考了98分!下次争取考一百分!有三个男生考了一百分

  • 学习内容

    今天学习了道德与法制《开开心心上学校》《爱新书爱书包》数学学习了1-5正确书写!语文金木水火土上口耳手足

  • 学习内容

    今天我们上折纸课!老师教我们叠小鱼!因为我上接送站没有带彩纸!是我的同学魏路德送给我的的!

网友评论

      本文标题:12月26日学习内容

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