码迷,mamicode.com
首页 > 编程语言 > 详细

Linux运维系统工程师与java基础学习系列-8

时间:2014-08-21 19:41:45      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:linux运维 java运维技术 java运维基础

Java天生骄傲系列-8

  函数的应用(重点掌握

如何定义函数

         1

                             package test.myeclipse;

                publicclass test1 {

                                  publicstaticvoid main(String[]args) {

                                      int Sum = getSum();

                                      System.out.println("Sum="+Sum);

          

                                   }      

      

                                  publicstaticint getSum()

                                  {

                                      return 3+4;

                                  }

 

                }

            运行结果:Sum=7

 

        例2

                package test.myeclipse;

                publicclass test1 {

                                  publicstaticvoid main(String[]args) {

                                     int Sum = getSum(5,7);

                                     System.out.println("Sum="+Sum);

                                   }     

      

                                  publicstaticint getSum(int x,int y)

                                  {

                                      return x+y;

                                  }

 

                }

 

            运行结果:Sum=12

 

 

        牛刀小试:

                          packagetest.myeclipse;

            publicclass test1 { 

                              publicstaticvoid main(String[]args) {

                                  draw(5,6);          

                               }

                              publicstaticvoid draw(int row,int col)

                              {

                                  for(int x=0;x<row;x++)

                                  {  

            for(int y=0;y<col;y++)

                                     {

                                         System.out.print("*");

                                     }

                                     System.out.println();

                                  }

          

                              }

         

            }

        运行结果:

                          ******

        ******

        ******

        ******

        ******



未完待续......


本文出自 “空谷幽兰” 博客,请务必保留此出处http://2489843.blog.51cto.com/2479843/1543141

Linux运维系统工程师与java基础学习系列-8,布布扣,bubuko.com

Linux运维系统工程师与java基础学习系列-8

标签:linux运维 java运维技术 java运维基础

原文地址:http://2489843.blog.51cto.com/2479843/1543141

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!