Defines a method with a parameter return value to implement an array of output random numbers

Source: Internet
Author: User

public class Mains {

public static void Main (string[] args) {

Create object, object named Hello

Mains hello = new mains ();

Calling a method and saving the return value in a variable

int[] Nums = Hello.getarray (8);

Converts an array to a string and outputs

System.out.println (arrays.tostring (nums));

}


/*

* Function: Creates an array of type int of the specified length and generates a value for each element in an array of 100 or less random numbers

* Defines a method with the return value of the parameter, passing in the length of the array, returning the array after the assignment

*/

Public int[] GetArray (int length) {

Defines an integer array of the specified length

int[] Nums = new Int[length];

Iterating through an array assignment

for (int i=0; i<nums.length;i++) {

Generates a random number within 100 and assigns to each member of the array

int a= (int) (Math.random () *100);

Nums[i]=a;

}

return nums; Returns the array after assignment

}


}


Defines a method with a parameter return value, implementing an array of output random numbers

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.