From 6464e418de83eb9a4465406682fe40e7f3d5a038 Mon Sep 17 00:00:00 2001 From: Ishani <91597584+IshuC19@users.noreply.github.com> Date: Mon, 10 Oct 2022 22:37:05 +0530 Subject: [PATCH] Create Print the Smallest Element in an Array.java --- Print the Smallest Element in an Array.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Print the Smallest Element in an Array.java 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]