Skip to content

Instantly share code, notes, and snippets.

@makiftutuncu
Created November 29, 2015 21:10
Show Gist options
  • Save makiftutuncu/1b7264a555fd897f2a77 to your computer and use it in GitHub Desktop.
Save makiftutuncu/1b7264a555fd897f2a77 to your computer and use it in GitHub Desktop.
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