Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Print the Smallest Element in an Array.java
Original file line number Diff line number Diff line change
@@ -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] <min)
min = arr[i];
}
System.out.println("Smallest element present in given array: " + min);
}
}