Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Maximum and Minimum in an Array by User's Input ///
- import java.util.Scanner;
- public class MaxMin {
- public static void main(String[] args) {
- int [] sampleArray;
- sampleArray=new int[50];
- int i,maximum,minimum,size;
- Scanner scan=new Scanner(System.in); /// Scan Line ///
- /// In This Line You have to input the Size of your Array ///
- System.out.println("Enter the Size of your Array: ");
- size=scan.nextInt();
- System.out.println("Enter the Elements of your Array: ");
- for (i=0;i<size;i++)
- {
- sampleArray[i]=scan.nextInt(); /// Array Input ///
- }
- maximum=sampleArray[0];
- minimum=sampleArray[0];
- for (i=0;i<size;i++)
- {
- if (sampleArray[i] > maximum)
- {
- maximum=sampleArray[i];
- }
- else if (sampleArray[i] < minimum)
- {
- minimum=sampleArray[i];
- }
- }
- System.out.println("Maximum Number is : " +maximum);
- System.out.println("Minimum Number is : " +minimum);
- }
- }
- /// Finished.Happy Coding ///
Add Comment
Please, Sign In to add comment