Java方法查漏补缺

Java方法查漏补缺

一:

package com.oop;
import java.io.IOException;
import java.util.Scanner;
// Demo01 类
public class Demo01 {
    // main 方法
    public static void main(String[] args) {
        int sum = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.println("please enter two counts choose the bigger count:");
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        sum = max(a,b);
        if (sum == 0){
            System.out.println(b);
        }else {
            System.out.println(a);
        }
        scanner.close();
    }
    /*
        修饰符 返回值类型 方法名字(...){
            方法体
            return 返回值;
        }
     */
    public static String sayHello(){
        return "Hello World"; // return代表方法结束 返回一个结果
    }
    public static int max(int a,int b){
        return a > b ? 1 : 0; // 三元运算符
    }

}

二:

package com.oop;
public class Demo02 {
    // 静态方法 static

    // 非静态方法

    public static void main(String[] args) {
        Student.speak(); // 静态方法调用
        // 非静态方法调用:(常用)
        // 实例化这个类 new
        // 对象类型 对象名字 = 对象值;
        Student student = new Student();
        student.say();
    }
    // static 和类一起加载
    public void a(){
        b();
    }
    // 类实例化 后才存在
    public void b(){}
}

三:

package com.oop;
public class Demo04 { // 值传递与引用传递练习
    public static void main(String[] args) {

    }
    // 返回值为空
    public static void change(int a){
        a = 10;
    }
}

四:

package com.oop;
/***
 * ░░░░░░░░░░░░░░░░░░░░░░░░▄░░
 * ░░░░░░░░░▐█░░░░░░░░░░░▄▀▒▌░
 * ░░░░░░░░▐▀▒█░░░░░░░░▄▀▒▒▒▐
 * ░░░░░░░▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐
 * ░░░░░▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐
 * ░░░▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌
 * ░░▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒
 * ░░▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐
 * ░▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄
 * ░▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒
 * ▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒
 * 单身狗就这样默默地看着你,一句话也不说。
 */
public class Demo05 { // 引用传递
    public static void main(String[] args) {
        Person person = new Person();
        System.out.println(person);
        System.out.println(person.name);
        Demo05.change(person);
        System.out.println(person.name);
    }
    public static void change(Person person){
        // person是一个对象 指向的是------>Person person = new Person();这是一个具体的人 可以改变属性
        person.name = "LittleWu";
    }
}
// 定义了一个Person类 有一个属性:name
class Person{
    String name;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值