for loop
import java.util.ArrayList;
public class Main {
public static void main(String[]ar){
//ArrayList in java
//ArrayList main koi limet nahi hota is amin aap no limet Item daal sakty ho
// <>k anda aap data type btasakty ho jisa k is main<String> data type add hy
// sintax ArrayList<data type> aryVriableName = new ArrayList();
ArrayList<String> arrayList = new ArrayList();
//arryList main Value add krna
//is main sirf String add hosakta hy
arrayList.add("0");
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");
arrayList.add("5");
arrayList.add("6");
arrayList.add("7");
// Loops in java
// loop 3 tarha k hoty hain
// 1. while loop
// 2. do while loop
// 3. for loop
// for loop
//jab tak i ka size arrayList k size sy choti hogi
//array main jo Value hogi print hoti rahy gi
//to array main 8 Values hy sab print hogi 0 1 2 3 4 5 6 7
//i ki Value 0 hy or arrayList ki 8 hy
//to ham java ko bataty hi k i ko print kar k i
//value ky sath 1+ kar k pir sy print kardo or aysa tab tak karna
// jab tak i ke value arrayList k size jo k 8 hy sy choti < ho
// i++ matlab i + i+1 i k mojoda value ky sath 1 + karna
for (int i=0; i<arrayList.size();i++){
System.out.println(arrayList.get(i));
}
}
}
Comments
Post a Comment