From f0a12a7bc9e429a639c25d08a499b292b73784cf Mon Sep 17 00:00:00 2001 From: Vaidehi Bhardwaj <61655574+Vaidehi0421@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:03:06 +0530 Subject: [PATCH] Added a program in java Added a program in java to find the maximum and minimum in an array. --- Java/program-1/README.md | 9 +++++++++ Java/program-1/program.java | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Java/program-1/README.md create mode 100644 Java/program-1/program.java diff --git a/Java/program-1/README.md b/Java/program-1/README.md new file mode 100644 index 00000000..5bf7551a --- /dev/null +++ b/Java/program-1/README.md @@ -0,0 +1,9 @@ +Program 1 + +Write a program to find the maximum and minimum element in an array. + +Variable description-- +N=Number of elements in an array +arr=Array of size N +min= Holds the minimum element +max=Holds the maximum element \ No newline at end of file diff --git a/Java/program-1/program.java b/Java/program-1/program.java new file mode 100644 index 00000000..8abc89cd --- /dev/null +++ b/Java/program-1/program.java @@ -0,0 +1,24 @@ +import java.util.*; +import java.io.*; + +class prg { + public static void main (String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("Enter the size of array"); + int N=sc.nextInt(); + int arr[]=new int[N]; + System.out.println("Enter the elements in the array"); + for(int i=0;imax) + max=arr[i]; + } + System.out.println("Minimum="+min+"\nMaximum="+max); + } +} \ No newline at end of file