读书笔记-----Java语句、数组

if后面是布尔类型
表示两个相等是用 equals
eg:sex=”女“;
     if(sex.equals("女")).....
switch语句中,case后面要跟多个参数,例如:case 1:case 2:case 3:System.out.println("我饿了");berak;
while语句,先判断再操作,do while语句是先操作再判断(do while 语句需要无条件操作一次)
break:结束整个循环。continue:结束本次循环,看是否进入下一个循环
数组:int[] stu;(整型数组定义)
          String[] stu;(字符型数组定义)
          double[] stu;(浮点型数组定义)
          数组名 = new  数据类型 [ 数组长度 ];(分配空间)
          数组下标从0开始。
          数组赋值:eg:1、int[] num={1,5,6,7,8};
                                2、int[] num=new int[5];
                                     num[0]=1;
                                     num[1]=5;
                                     ..........
在System.out.println();在括号里有加" "," "里原样输出.eg:
    public class cyb{
        public static void main(String[] args) {
            int classNum=3;
            System.out.println(classNum);
        }
    }
结果:3
    public class cyb{
        public static void main(String[] args) {
            int classNum=3;
            System.out.println("classNum");
        }
    }
结果: classNum

Arrays.toString(数组名);【转换为字符型】
Arrays.sort(数组名);【排序】
import java.util.Arrays;
public class cyb{
    public static void main(String[] args) {
        String[] subject = { "math", "chinese", "english" };
        Arrays.sort(subject);
        System.out.println("排序后数组中的元素:"+Arrays.toString(subject) );
    }
}

foreach:
for(变量类型 变量:总对象)

public class cyb {
    public static void main(String[] args) {
        int[] scores = {90,89,91,75,94};
        for(int i=0;i<scores.length;i++){            
            System.out.println(scores[i]);
        }
        //等价
        /*for (int score : scores ) {
            System.out.println(score);
          }*/
    }
}

数组替换
public class cyb {
    public static void main(String[] args) {
        int[] score = new int[] {1,4,3,87,100};
        int max = score[0]; 
        int min = score[0]; 
          
        for (int i = 0; i < score.length; i++) { 
            if(score[i]>max){
                max=score[i];
            }
            if(score[i]<min){
                min=score[i];
            }
        }     
        System.out.println("数组中的最大值:" + max);
        System.out.println("数组中的最小值:" + min);
    }
}

二维数组
type[][] 变量={值1,值2,值3,...},{值1,值2,值3,...};(大括号代表行,值代表列)

type[][] 变量=new type[][];
变量[行][列]=值;


 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值