diff --git a/Print the Smallest Element in an Array.java b/Print the Smallest Element in an Array.java new file mode 100644 index 0000000..a620883 --- /dev/null +++ b/Print the Smallest Element in an Array.java @@ -0,0 +1,16 @@ +public class SmallestElement_array { + public static void main(String[] args) { + + //Initialize array + int [] arr = new int [] {20, 10, 7, 84, 65}; + //Initialize min with first element of array. + int min = arr[0]; + //Loop through the array + for (int i = 0; i < arr.length; i++) { + //Compare elements of array with min + if(arr[i]