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