Sunday, February 23, 2014
Two types of for loops for a variable which holds full of values
//Two types of for loops for a variable which holds full of values
public class miscelleneous {
public static void main(String[] args) {
// TODO Auto-generated method stub
miscelleneous obj1=new miscelleneous();
//System.out.println(obj1); // this is a valid code because object is instance of class it has address of portion of class
//System.out.println(new miscelleneous()); // this syntax is similar to above code for objects..here also object is created
//System.out.println();
String[] array = new String[2];
for(int i = 0; i < array.length; i++) //for(String s:array)
{
//array[0]="1";
String s = array[i];
//System.out.println(s);
}
//String args1[];
for (String s1: array) // Data type, variable and array name. This for loop will go till size of an array
// s1 gets successively each value in array
//http://www.leepoint.net/notes-java/flow/loops/foreach.html
{
array[0]="2";
System.out.println(array[0]);
//System.out.println(s1); // s1=array(0);
//s1=array[0];
System.out.println(s1); //s1 gets each value of an array
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment