当前位置:首页 > 操作系统 > Linux

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

Java天生骄傲系列-8

   函数的应用( 重点掌握

如何定义函数

         1

                             package test.myeclipse;

                public class test1 {

                                  public static void main(String[]args) {

                                       int Sum = getSum();

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

          

                                   }       

      

                                  public static int getSum()

                                  {

                                      return 3+4;

                                  }

 

                }

            运行结果: Sum=7

 

        例 2

                package test.myeclipse;

                public class test1 {

                                   public static void main(String[]args) {

                                      int Sum = getSum(5,7);

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

                                   }      

      

                                   public static int getSum( int x, int y)

                                  {

                                       return x+y;

                                  }

 

                }

 

            运行结果: Sum=12

 

 

        牛刀小试:

                          packagetest.myeclipse;

            public class test1 {  

                               public static void main(String[]args) {

                                  draw(5,6);           

                               }

                               public static void 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

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


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!