Rangeクラスの3つの方法と簡単な印刷

15666 ワード

  1 package pkgFirst;
  2 
  3 import org.junit.Test;
  4 
  5 public class Range{
  6     
  7     /**
  8       * FunName:        println
  9       * Description :    , System.out.println(object)
 10       * @param:                 object being print
 11       * @return String:  none
 12       * @Author:        Bingoreo
 13       * @Create Date:   2015-07-15
 14       **/
 15     public static void println(Object obj){
 16         System.out.println(obj);
 17     }
 18     /**
 19       * FunName:        print
 20       * Description :    , System.out.print(object)
 21       * @param:                 object
 22       * @return String:  none
 23       * @Author:        Bingoreo
 24       * @Create Date:   2015-07-15
 25       **/
 26     public static void print(Object obj){
 27         System.out.print(obj);
 28         
 29     }
 30     /**
 31       * FunName:        println
 32       * Description :    , System.out.println()
 33       * @param:                 none
 34       * @return String:  none
 35       * @Author:        Bingoreo
 36       * @Create Date:   2015-07-15
 37       **/
 38     public static void println(){
 39         System.out.println();
 40     }
 41     @Test
 42     /**
 43       * FunName:        range
 44       * Description :    0 n-1 , 1
 45       * @param:                 int n
 46       * @return String:   
 47       * @Author:        Bingoreo
 48       * @Create Date:   2015-07-15
 49       **/
 50     public static int[] range(int n){
 51         if (n <=0)
 52                 return null;
 53         else {
 54             int[] inCount = new int[n];
 55             for(int i =0; i<n ; i++){
 56                 inCount[i] = i;
 57             }
 58             return inCount;
 59         }
 60     }
 61     @Test
 62     /**
 63       * FunName:        range
 64       * Description :    start end-1 , 1
 65       * @param:                 start, start
 66       * @return String:   
 67       * @Author:        Bingoreo
 68       * @Create Date:   2015-07-15
 69       **/
 70     public static int[] range(int start, int end){
 71         if (start >= end)
 72             return null;
 73         else{
 74             int[] inCount = new int[end - start];
 75             for(int i =0; i<end-start ; i++){
 76                 inCount[i] = end - start + i;
 77             }
 78             return inCount;
 79         }
 80     }
 81     /**
 82       * FunName:        range
 83       * Description :    start end , step
 84       * @param:                 start, end,step
 85       * @return String:   
 86       * @Author:        Bingoreo
 87       * @Create Date:   2015-07-15
 88       **/
 89     public static int[] range(int start, int end, int step){
 90         
 91         if (start >= end)
 92             return null;
 93         else{
 94             int n = (end - start)/step + 1;
 95             int[] inCount = new int[n];
 96             for(int i =0; i<n ; i++){
 97                 inCount[i] = (end - start) + step*i;
 98             }
 99             return inCount;
100         }
101     }
102     
103     public static void main(String[] args) {
104         // TODO  
105         //SimplePrintOne sp = new SimplePrintOne();
106         //sp.println("simple printLn");
107         //sp.print("simple print");
108         //for(int x :range(10,20,12))
109             //System.out.print(x+" ");
110 
111         }
112     }