Method createNewArray that accepts one integer parameter for sizing the integer array the method will return. The method will create a new integer array of the size specified by the parameter, fill it with random values from 1 thru 100 (inclusive) and return the new array.
Program:
import java.util.*;
class CreateArray
{
public static int[] createNewArray(int size)
{
int newArray[]=new int[size];
Random ran=new Random();
for(int i=0;i<size;i++)
{
newArray[i]=(int)(Math.random()*(100-1)+1);
//(int)(Math.random()*(upper-lower)+lower)
}
return newArray;
}
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
System.out.print("\nEnter the size of the array: ");
int size=input.nextInt();
int newArray[]=new int[size];
newArray=createNewArray(size);
System.out.println("\nArray elements :\n");
for(int i=0;i<size;i++)
{
System.out.print(newArray[i]+"\t");
}
System.out.println("\n");
}
}
Output:

Method createNewArray that accepts one integer parameter for sizing the integer array the method will return....
Create 3 user-defined methods called add(). 1 accepts a single integer array parameter; this method should loop the array adding the values and return the summation (use 4, 1, 4, 6, 10, 15, 32, 79, 18 as the values in the array) 1 accepts 2 integer parameters; this method should add them and return the value 1 accepts 3 integer parameters; this method should add them all and return the value In main, define the parameters above (you may use...
Create in C# Write a method called MaximumDiffrence that accepts an integer array as a parameter and return the maximum difference between adjacent values in the array, where the gap is defined as the absolute value of the difference between the 2 adjacent values. Example: if the array contains {5, 7, 4, 9, 6, 12, 8} so The first gap is (5,7)=-2 and the absolute value is 2 The second gap is (7,4)=3 Third gap is (4,9) = -5 its...
A private class method named findMaximum that accepts the array of weights as a parameter together with the number of valid weights it contains. It should return the largest weight in that array. each objects contain one integer and one double Weight(int, double) private static Weight findMaximum(Weight[] objects) { }
Write a method named printReverse() that accepts an int array as its parameter and prints that array in reverse order. This method should not have a return statement (void). - All elements should be printed on the same line, separated by a space - A new line should be printed after the entire array prints - If the array passed in held the values: {3,2,1} - Output: 1 2 3 //newline printed here
Write a method named factorial that accepts an integer n as a parameter and returns the factorial of n, or n!. A factorial of an integer is defined as the product of all integers from 1 through that integer inclusive. For example, the call of factorial(4) should return 1 2 3 4, or 24. The factorial of 0 and 1 are defined to be 1. You may assume that the value passed is non-negative and that its factorial can fit...
. In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...
In matlab, there is a function "size" that accepts an array as a
parameter (or input argument) and returns the dimensions of that
array as another single-dimension array.
For example, if the array were 2 x 2, it
would return [2 2]. Assume that input1 is a 1 or 2-dimensional
array. Use the size function to obtain the dimensions and save the
output into the return argument of this function "output1"
1Do not modify the line below 2-unction...
java
/* Q2 (10 pts): Write a method called method that accepts an integer parameter * * * * and returns a sum of the first n terms of the sequence. * In other words, the method should generate the following sequence: 1 + 1/2 + 1/3 + 1/4 + ... 1/n * For example, method2(2) will return 1.5 since 1+1/2 = 1.5 * method2 (15) will return 3.3182289932289937 * You may assume that the parameter n is nonnegative. */...
9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named...
In Java Write a method factorial that accepts an integer parameter n and that uses recursion to compute and return the value of n factorial (also known as n!). Your method should throw an IllegalArgumentException if n is negative. Several calls and their return values are shown below. Call Output factorial(0); 1 factorial(1); 1 factorial(3); 6 factorial(5); 120 factorial(10); 3628800 factorial(-4); IllegalArgumentException