Java学习----你可以知道对象的工作结果(获取方法的返回值)

1.写返回类型

2.return 返回值

3.定义变量接受返回值

public class App2 {
    public String [] print(String msg, int num) {
        for (int i = 0; i < num; i++) {
            System.out.println(msg);
        }
        return new String[]{"aaa","bbb"};
    }
    
    public static void main(String[] args) {    
        App2 obj = new App2();
        String[] x = obj.print("hello world", 5);
        System.out.println(x[0]);
        System.out.println(x[1]);
    }
}

执行结果:

hello world
hello world
hello world
hello world
hello world
aaa
bbb
原文地址:https://www.cnblogs.com/dragon1013/p/5051366.html