day08-java

数组使用

1.for-each循环

2.作为方法参数,例:public static int function(int[] array){...};

3.作为方法返回值,例:public static int[] function(...){...};

多维数组

int[][] array = new int[2][3];

Arrays类

 面向对象

 

package com.shifan.oop.demo01;

public class Demo01 {
    public static void main(String[] args) {
        //修饰符static表示该方法为静态方法,可以直接使用类名调用
        System.out.println(Demo01.add(1,4));
        //同一类中的静态方法中可直接调用其他静态方法
        int sum = add(1,2);
        sum = Demo01.add(2,4);
        System.out.println(sum);
        /*同一个类中静态方法不能直接调用非静态方法
          静态方法与类同时加载,非静态方法在类实例化后才加载
        例如:int a = fun(2,1);错误*/
        /*静态方法中不能直接调用非静态方法,需要先实例化这个类
        例如:Student.print();错误*/
        //实例化Student类
        Student student = new Student();
        student.print();
    }
    public static int add(int a ,int b){
        return a+b;
    }
    public int fun(int a,int b){
        return a-b;
    }
}
package com.shifan.oop.demo01;

public class Demo02 {
    public static void main(String[] args) {
        Person person = new Person();
        System.out.println(person.name);
        change(person);
        System.out.println(person.name);
    }
    public static void change(Person person){
        person.name = "时帆";
    }
}
/**定义了一个Person类,有一个属性name
 * 一个类里面只能有一个public,但可以有多个class
 */
class Person{
    String name;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值