Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static double minElement(double[] array){
  4. double min = array[0];
  5. int minIndex = 0;
  6. for (int index = 0; index < array.length; index++) {
  7. if(min > array[index]){
  8. min = array[index];
  9. minIndex = index;
  10. }
  11. }
  12. return min;
  13. }
  14.  
  15. public static void main(String[] args) {
  16. Scanner in = new Scanner(System.in);
  17. System.out.print("Input array length: ");
  18. int num = in.nextInt();
  19. while (num > 25) {
  20. System.out.print("Input array length, it must be lower than 25: ");
  21. num = in.nextInt();
  22. }
  23. System.out.print("Input p: ");
  24. int p = in.nextInt();
  25. while (p <= 2) {
  26. System.out.print("Input p, it must be greater than 2: ");
  27. p = in.nextInt();
  28. }
  29. double array[] = new double[num];
  30. for (int index=0; index < array.length; index++){
  31. array[index] = 0.5*p + (int) (Math.random() * 3.5*p);
  32. System.out.println(array[index]);
  33. }
  34. System.out.println( minElement(array));
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement