Bu örnekte 50-100 arası rastgele üretilen sayıların ortalamasını hesaplayıp ekrana yazdıracağız.
Örneğe başlamadan önce Java Rastgele Sayı Üretme sayfasını ziyaret edebilirsiniz.
package kodbloklari.com;
import java.util.Random;
public class Random2 {
public static void main(String[] args) {
Random rastgele = new Random();
int sayi;
float toplam = 0;
for(int i = 0; i < 10; i++)
{
sayi = 50 + rastgele.nextInt(50);
System.out.println(sayi);
toplam += sayi;
}
System.out.println("Sayıların ortalaması = " +(toplam / 10));
}
}
50 ile 100 arasında değerler üretmek istediğimiz için 0 – 50 arası üretilen değerlere 50 ekledik.
Kodun ekran çıktısı şu şekildedir:

2 Yorum
Appreciating the persistence you put into your blog and in depth information you provide. It’s nice to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read! I’ve saved your site and I’m including your RSS feeds to my Google account.
I am always thought about this, thankyou for putting up.