Created
September 3, 2020 14:40
-
-
Save mrnirva/cd14c5a520ee672a5b4e5a171fd6435d to your computer and use it in GitHub Desktop.
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
package arrayssinifi; | |
public class ArraysSinifi { | |
public static void main(String[] args) { | |
String[] arrayim = {"Ali","Veli","Fatma"}; | |
// Döngüyle dizinin içerisindeki elemanları yazdırma | |
// i = 0 koşulu başlangıcı 0. indisten yap demek | |
// i<arrayim.length -> dizinin boyutu kadar git | |
// i++ her defasında i'ye bir ekle | |
// Bu sayede arrayim[i] ile 0. indisten başlayıp | |
// dizinin son indisine kadar gideriz | |
for(int i=0; i<arrayim.length; i++){ | |
System.out.println(arrayim[i]); | |
} | |
/* | |
Çıktı: | |
Ali | |
Veli | |
Fatma | |
*/ | |
// Döngüyle dizinin içerisine eleman atamak | |
// Aşağıdaki örnekte dizi içerisine çift sayıları ekledik | |
// Her defasında degeri 2 arttırdık bu sayede çiftleri elde ettik | |
int[] ciftSayilar = new int[10]; | |
int deger = 0; | |
for(int i=0; i<ciftSayilar.length; i++){ | |
ciftSayilar[i] = deger; | |
deger += 2; | |
} | |
// Döngüyle diziyi yazdırma | |
for(int i=0; i<ciftSayilar.length; i++){ | |
System.out.println(ciftSayilar[i]); | |
} | |
/* | |
Çıktı: | |
0 | |
2 | |
4 | |
6 | |
8 | |
10 | |
12 | |
14 | |
16 | |
18 | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment