Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static double minElement(double[] array){
- double min = array[0];
- int minIndex = 0;
- for (int index = 0; index < array.length; index++) {
- if(min > array[index]){
- min = array[index];
- minIndex = index;
- }
- }
- return min;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.print("Input array length: ");
- int num = in.nextInt();
- while (num > 25) {
- System.out.print("Input array length, it must be lower than 25: ");
- num = in.nextInt();
- }
- System.out.print("Input p: ");
- int p = in.nextInt();
- while (p <= 2) {
- System.out.print("Input p, it must be greater than 2: ");
- p = in.nextInt();
- }
- double array[] = new double[num];
- for (int index=0; index < array.length; index++){
- array[index] = 0.5*p + (int) (Math.random() * 3.5*p);
- System.out.println(array[index]);
- }
- System.out.println( minElement(array));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement