From 76ce1d698bf2ddf3bdf2f995a67c5b631e5ef95e Mon Sep 17 00:00:00 2001 From: harsh06s <145155205+harsh06s@users.noreply.github.com> Date: Fri, 20 Oct 2023 00:48:11 +0530 Subject: [PATCH] Create max_arr.java --- max_arr.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 max_arr.java diff --git a/max_arr.java b/max_arr.java new file mode 100644 index 0000000..b37e27d --- /dev/null +++ b/max_arr.java @@ -0,0 +1,20 @@ +public class MaxNumberInArray { + public static void main(String[] args) { + int[] numbers = {10, 5, 20, 8, 15}; + + if (numbers.length == 0) { + System.out.println("The array is empty."); + return; + } + + int max = numbers[0]; + + for (int number : numbers) { + if (number > max) { + max = number; + } + } + + System.out.println("The maximum number in the array is: " + max); + } +}