Berilgan massiv elementlari ichidan eng kichik elementi topilsin.
public class DemoApplication {
public static void main(String[] args) {
// SpringApplication.run(DemoApplication.class, args);
Scanner scanner=new Scanner(System.in);
//Ma`lumotlarni qo’l bilan kiritishimni aytib o`tyapman
System.out.println("Massiv o`lchamini kiriting");
int n=scanner.nextInt();
int ar[] = new int[n];
//massiv elementlarni e’lon qilyapman
for (int i = 0; i System.out.println("Elementni kiriting:->");
ar[i]=scanner.nextInt();
}
System.out.printf("Eng kichik element:%s",min(ar));
}
//min degan mtod orqali minimal elementni qaytarayapti
public static int min(int ar[])
{ int ar_min = ar[0];
for (int i = 0; i < ar.length; i++)
{
if(ar[i] < ar_min)
ar_min = ar[i];
}
return ar_min;
};
}
Do'stlaringiz bilan baham: |