Overview For todays lab you will create a wellcommented java
Solution
//Code for the first 3 queries
public class Lab_01_ArrayUtilities {
private static double[] anArray; //array declaration
public static void builtInArray(int length,int fromNum,int toNum) //static method bubiltin array
{
anArray = new int[length]; // create the Array with given length
anArray[0]=fromNum;
anArray[length-1]=toNum;
for (int i = 1; i < =length-2; i++) // create a loop to load the array
{
anArray[i] = fromNum + (int)(Math.random()* ( toNum - fromNum + 1));//generates random number between given numbers and stores in array
}
}
public static void swap (int[] nums,int i,int j)//static method for swap
{
int[] n = int[] nums;
int temp = n[i]; // swaps n[3] and n[4]
n[i] = n[j];
n[j] = temp;
}
public static void OddNumbers(int[] nums)//OdNumbers method
{
int count =0 ;
int lenght=nums.length;
System.out.println(\"Elements in array are:\");
for(int i = 0 ; i < length; i++){
System.out.println(a[i]+\',\');
}
for(int i = 0 ; i < length; i++)
{
if(a[i] % 2 != 0)
count++;
}
System.out.println(\"OddNumbers\"+ count);
}
public static void main(String[] args) {
//By using class name, you can call static method
int [ ] Array = Lab_01_ArrayUtilities.builtInArray(20,5,30);//creates array with 20 elements between 5 and 30 including 5 and 30 values in array.
Lab_01_ArrayUtilities.swap( Array,2,3 ); ///swap 2nd 3 rd index vallues of the array object created above
OddNumbers(Array);
}
}
