Created
November 29, 2015 21:10
-
-
Save makiftutuncu/1b7264a555fd897f2a77 to your computer and use it in GitHub Desktop.
Neden Scala? yazısı için örnek Java kodu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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