Advertisement
Abir_Ahsan

JAVA-Max/Min

Oct 20th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1.  
  2. package javaapplication2;
  3.  
  4.  
  5. public class ArrayMaxMin
  6. {
  7.  
  8. public static void main(String[] args)
  9. {
  10. int[] a= new int[]{2,8,-11,3,4,2,90};
  11. int max,min;
  12. max=a[0];
  13. min=a[0];
  14.  
  15. for(int i=0; i<a.length;i++)
  16. {
  17. if(max<a[i])
  18. {
  19. max=a[i];
  20. }
  21.  
  22. }
  23.  
  24. for(int j=0;j<a.length;j++)
  25. {
  26. if(min>a[j])
  27. {
  28. min=a[j];
  29. }
  30. }
  31.  
  32. System.out.printf(" MAX:: %d \n",max);
  33. System.out.printf(" MIN:: %d ",min);
  34.  
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement