Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please follow the instuction ,, this program should be written in java Exercise

ID: 3599760 • Letter: P

Question

please follow the instuction ,,

this program should be written in java

Exercise 1: Write a program called FindSmallest to create a 1D array with 10 integer variables. The value of each integer variable in the 1D array will be set as a random number between 1 and 100. After the 1D array is initialised, write a method to find the smallest number among the 10 integers in the 1D array. The output of the program should firstly display all integers in the 1D array, and then indicate the smallest integer among them as wel as the index of the smallest integer in the 1D array

Explanation / Answer

FindSmallest.java

import java.util.Random;

public class FindSmallest {

public static void main(String[] args) {
//Creating an integer array
int ID[] = new int[10];

//Creating an random class object
Random r = new Random();

//Initializing the array elements with random numbers
for (int i = 0; i < ID.length; i++) {
ID[i] = r.nextInt((100 - 1) + 1) + 1;
}

//Displaying the array elements
System.out.println("__ Displaying the elements in the Array __");
for (int i = 0; i < ID.length; i++) {
System.out.print(ID[i] + " ");
}

//calling the method
findSmallestNum(ID);
}

//This method will find the minimum element in teh rray and its position
private static void findSmallestNum(int[] ID) {
int min = ID[0];
int index = 0;
for (int i = 0; i < ID.length; i++) {
if (min > ID[i]) {
min = ID[i];
index = i;
}
}

System.out.println(" The Smallest element in the array is " + min + " and is found at the posiition " + index);
}

}
package org.students;

import java.util.Random;

public class FindSmallest {

public static void main(String[] args) {
//Creating an integer array
int ID[] = new int[10];

//Creating an random class object
Random r = new Random();

//Initializing the array elements with random numbers
for (int i = 0; i < ID.length; i++) {
ID[i] = r.nextInt((100 - 1) + 1) + 1;
}

//Displaying the array elements
System.out.println("__ Displaying the elements in the Array __");
for (int i = 0; i < ID.length; i++) {
System.out.print(ID[i] + " ");
}

//calling the method
findSmallestNum(ID);
}

//This method will find the minimum element in teh rray and its position
private static void findSmallestNum(int[] ID) {
int min = ID[0];
int index = 0;
for (int i = 0; i < ID.length; i++) {
if (min > ID[i]) {
min = ID[i];
index = i;
}
}

System.out.println(" The Smallest element in the array is " + min + " and is found at the posiition " + index);
}

}

__________________

Output:

__ Displaying the elements in the Array __
51 6 41 35 100 85 51 14 72 10
The Smallest element in the array is 6 and is found at the posiition 1

_____________Could you rate me well.Plz .Thank You