Java programming ideology _ 008 generate a specified array class

Source: Internet
Author: User
Package WZS. test2; import Java. util. arrays; // generate the specified array class public class test {public static void main (string [] ARGs) {int [] a1 = rang (10 ); int [] a2 = rang (2, 10); int [] a3 = rang (2, 10, 2); system. out. println ("A1:" + arrays. tostring (A1); system. out. println ("A2:" + arrays. tostring (A2); system. out. println ("A3:" + arrays. tostring (A3);}/*** 0 -- N * @ Param N * @ return */public static int [] rang (int n) {int [] result = new int [N]; for (INT I = 0; I <n; I ++) {result [I] = I;} return result ;} /*** start -- end * @ Param start * @ Param end * @ return */public static int [] rang (INT start, int end) {int size = end-start; int [] result = new int [size]; for (INT I = 0; I <size; I ++) {result [I] = start + I;} return result ;} /*** start -- end step: Step * @ Param start * @ Param end * @ Param step * @ return */public static int [] rang (INT start, int end, int step) {int size = (end-Start)/step; int [] result = new int [size]; for (INT I = 0; I <size; I ++) {result [I] = start + I * step;} return result ;}}

Output result:

a1:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]a2:[2, 3, 4, 5, 6, 7, 8, 9]a3:[2, 4, 6, 8]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.