package arrray;
/**
*
*/
public class Arrray {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int []arynums;
arynums=new int[4];
arynums[0]=11;
arynums[1]=22;
arynums[2]=33;
arynums[3]=44;
/*or
int [ ]arynums={11,22,33,44};
except:-
boolean[ ] arybools=new boolean[ ] {true,false,true,false};
*/
System.out.println(arynums[3]);
}
}
use for loop:-
package arrray;
/**
*
*/
public class Arrray {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int [] lotterynums=new int[49];
int i;
for( i=0;i<lotterynums.length;i++)
{
lotterynums[i]=i+1;
System.out.print(lotterynums[i]+" ");
}
}
}
new method :-
package array_list;
import java.util.ArrayList;
/**
*
*/
public class Array_list {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ArrayList listtext=new ArrayList();
listtext.add("first item");
listtext.add("second item");
listtext.add("third item");
listtext.add(8);
listtext.remove("second item");
System.out.println("whole lists"+listtext);
System.out.println("position1= "+listtext.get(1));
}
}
0 التعليقات:
إرسال تعليق