返回列表 發帖

自訂函式 (一)

自訂函式:
1. void hello(int n)
2. int myPlus(int x,int y,int z)

  1. public class Ch50 {

  2.         static void hello(int n)
  3.         {
  4.                 for(int i=0; i<n; i++)
  5.                     System.out.println("Hello!!!");
  6.         }
  7.        
  8.         static int myPlus(int a, int b, int c)
  9.         {
  10.                 return a+b+c;
  11.         }
  12.        
  13.         public static void main(String[] args)
  14.         {
  15.                 hello(5);
  16.                 System.out.println(myPlus(1,2,3));
  17.         }
  18. }
複製代碼

  1. public class Ch10
  2. {
  3.         static void hello(int n)
  4.         {
  5.                 for(int i=1;i<=n;i++)
  6.                         System.out.println("Hello!");
  7.         }
  8.         static int myPlus(int a,int b,int c)
  9.         {
  10.                 return a+b+c;
  11.         }
  12.         public static void main(String[] args)
  13.         {
  14.                 hello(5);
  15.                 System.out.println(myPlus(1, 2, 3));
  16.         }
  17. }
複製代碼

TOP

  1. public class Ch02
  2. {
  3.         static void hello(int n)
  4.         {
  5.                 for (int i=0;i<n;i++)
  6.                         System.out.println("Hello!");
  7.         }       
  8.         static int myPlus(int a,int b,int c)
  9.         {
  10.                 return a+b+c;
  11.         }
  12.         public static void main(String[] args)
  13.         {
  14.                 hello(5);
  15.                 System.out.println(myPlus(1,2,3));
  16.         }
  17. }
複製代碼

TOP

  1. import java.util.Scanner;
  2. public class Ch01
  3. {
  4.         static void hello(int n)
  5.         {
  6.                 for(int i=1; i<=n; i++)
  7.                         System.out.println("Hello!");
  8.         }
  9.         static int myplus(int a,int b,int c)
  10.         {
  11.                 return a+b+c;
  12.         }
  13.         public static void main(String[] args)
  14.         {
  15.                 hello(5);
  16.                 System.out.println(myplus(1,2,3));
  17.         }
  18. }
複製代碼

TOP

  1. public class Ch01 {
  2.         static void hello(int n)
  3.         {
  4.                 for(int i=0; i<n; i++)
  5.                         System.out.println("Hello!!!");
  6.         }
  7.         static int myPlus(int a, int b, int c)
  8.         {
  9.                 return a+b+c;
  10.         }
  11.         public static void main(String[] args)
  12.         {
  13.                 hello(5);
  14.                 System.out.println(myPlus(1,2,3));
  15.         }
  16. }
複製代碼

TOP

  1. public class Ch02 {
  2.         static void hello(int n)
  3.         {
  4.                 for(int i=0;i<n;i++)
  5.                         System.out.println("Hello!!!");
  6.         }
  7.         static int myPlus(int a,int b,int c)
  8.         {
  9.                 return a+b+c;       
  10.         }
  11.         public static void main(String[] args) {
  12.                 hello(5);
  13.                 System.out.println(myPlus(1,2,3));
  14.         }

  15. }
複製代碼

TOP

  1. static void hello(int n)
  2.         {
  3.                 for(int i=0; i<n; i++)
  4.                     System.out.println("Hello!!!");
  5.         }
  6.       
  7.         static int myPlus(int a, int b, int c)
  8.         {
  9.                 return a+b+c;
  10.         }
  11.       
  12.         public static void main(String[] args)
  13.         {
  14.                 hello(5);
  15.                 System.out.println(myPlus(1,2,3));
  16.         }
複製代碼

TOP

  1. public class Ch05
  2. {
  3.         static void hello(int n)
  4.         {
  5.                 for(int i=0;i<n;i++)
  6.                         System.out.println("Hello!");
  7.         }
  8.         static int myPlus(int a,int b,int c)
  9.         {
  10.                 return a+b+c;
  11.         }
  12.         public static void main(String[] args)
  13.         {
  14.                 hello(5);
  15.                 System.out.println(myPlus(1, 2, 3));
  16.         }
  17. }
複製代碼

TOP

  1. public class Ch01 {
  2.         static void hello(int n)
  3.         {
  4.                 for(int i=0;i<n;i++)
  5.                         System.out.println("Hello");
  6.         }
  7.         static int myPlus(int a, int b,int c)
  8.         {
  9.                 return a+b+c;
  10.         }
  11.         public static void main(String[]args)
  12.         {
  13.                 hello(5);
  14.                 System.out.println(myPlus(1, 2, 3));

  15.         }




  16. }
複製代碼

TOP

  1. public class Ch01{
  2.        
  3.         static void hello(int n)
  4.         {
  5.                 for(int i=0; i<n; i++)
  6.                         System.out.println("Hello!!!");
  7.         }
  8.         
  9.         static int myPlus(int a, int b, int c)
  10.         {
  11.                 return a+b+c
  12.         }
  13.         
  14.             public static void main(String[] args)
  15.             {
  16.                 hello(5);
  17.                 System.out.println(myPlus(1,2,3));
  18.                
  19.             }
  20. }               
複製代碼

TOP

  1. public class AS02 {
  2.        
  3.         static void opt(int x){
  4.                 for(int i=x; i>0; i--)
  5.                         System.out.print("Output ");
  6.         }
  7.        
  8.         static float ave(int a, int b, int c){
  9.                 return (a+b+c)/3;
  10.         }

  11.         public static void main(String[] args) {
  12.                 opt(6);
  13.                 System.out.println(ave(9, 8, 6));

  14.         }

  15. }
複製代碼

TOP

返回列表