29 Eylül 2009 Salı

for döngüsü (For Statment)

class ForDemo {
public static void main(String[] args){
for(int i=1; i<11;>
The output of this program is:
Count is: 1
Count is: 2
Count is: 3
Count is: 4
Count is: 5
Count is: 6
Count is: 7
Count is: 8
Count is: 9
Count is: 10


veya...
class EnhancedForDemo {
public static void main(String[] args){
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
for (int item : numbers) {
System.out.println("Count is: " + item);
}
}
}
In this example, the variable item holds the current value from the numbers array. The output from this program is the same as before:
Count is: 1
Count is: 2
Count is: 3
Count is: 4
Count is: 5
Count is: 6
Count is: 7
Count is: 8
Count is: 9

Count is: 10

Kaynak: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html

Hiç yorum yok:

Yorum Gönder