Java Langauge Accept Positive Integer N Keyboard Create Array Arraylist Containing N Rando Q37151003

Java Langauge
Accept a positive integer n from keyboard and then create an arrayor arraylist containing n random elements within the range [−n,n].Print out the random array or arraylist,


Answer


import java.util.ArrayList;import java.util.Random;import java.util.Scanner;public class RandomList { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print(“Enter a positive integer for n: “); int n = in.nextInt(); ArrayList<Integer> list = new ArrayList<>();

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.