2014-12-01-1717-java-randomly generates an array of 8-bit numbers (100 or less)

Source: Internet
Author: User

Import Java.util.Arrays;

public class HelloWorld {public static void main (string[] args) {

Create object, object named Hello

HelloWorld Hello = new HelloWorld ();

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 the array that is within 100 random number

* 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<length;i++) {

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

nums[i]= (int) (Math.random () *100);

}

return nums;

Returns the array after assignment

}

}

2014-12-01-1717-java-randomly generates an array of 8-bit numbers (100 or less)

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.