首页 > 编程语言 > 详细

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

时间:2015-12-16 17:09:20      阅读:154      评论:0      收藏:0      [点我收藏+]

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

 

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

原文:http://www.cnblogs.com/dragon1013/p/5051366.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!