Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Neden Scala? yazısı için örnek Java kodu
class Insan {
private int yas;
public Insan(int yas) {
this.yas = yas;
}
public int yas() {
return yas;
}
@Override public String toString() {
return "Insan(" + yas + ")";
}
}
class NedenScala {
public static void main(String[] args) {
Random rastgele = new Random();
Insan[] insanlar = new Insan[10];
for (int i = 0; i < 10; i++) {
insanlar[i] = new Insan(rastgele.nextInt(30) + 5);
}
System.out.println("İnsanlar:");
for (Insan insan : insanlar) {
System.out.println(insan);
}
System.out.println("Yaşları toplamı:");
int toplam = 0;
for (Insan insan : insanlar) {
toplam += insan.yas();
}
System.out.println(toplam);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.