Guest User

Untitled

a guest
Jun 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. /// Maximum and Minimum in an Array by User's Input ///
  2. import java.util.Scanner;
  3. public class MaxMin {
  4. public static void main(String[] args) {
  5. int [] sampleArray;
  6. sampleArray=new int[50];
  7. int i,maximum,minimum,size;
  8. Scanner scan=new Scanner(System.in); /// Scan Line ///
  9.  
  10. /// In This Line You have to input the Size of your Array ///
  11. System.out.println("Enter the Size of your Array: ");
  12. size=scan.nextInt();
  13.  
  14. System.out.println("Enter the Elements of your Array: ");
  15. for (i=0;i<size;i++)
  16. {
  17. sampleArray[i]=scan.nextInt(); /// Array Input ///
  18. }
  19. maximum=sampleArray[0];
  20. minimum=sampleArray[0];
  21. for (i=0;i<size;i++)
  22. {
  23. if (sampleArray[i] > maximum)
  24. {
  25. maximum=sampleArray[i];
  26. }
  27. else if (sampleArray[i] < minimum)
  28. {
  29. minimum=sampleArray[i];
  30. }
  31. }
  32. System.out.println("Maximum Number is : " +maximum);
  33. System.out.println("Minimum Number is : " +minimum);
  34.  
  35. }
  36.  
  37. }
  38.  
  39. /// Finished.Happy Coding ///
Add Comment
Please, Sign In to add comment