import java.util.*;;
public class selection {
Scanner in=new Scanner(System.in);
private int size;
private int[] num=new int[size];
selection(int size){
this.size=size;
}
void enternum(){
System.out.print("enter number"+size);
for (int i=0;i<5;i++)
num[i]=in.nextInt();
}
void sort(){
for (int i=0;i<num.length;i++){
int min=i;
for(int j=i+1;j<num.length;j++){
if(less(num[i],num[j]))
excg(i,j);
}
}
display();
}
boolean less(int x,int y){
if(x>y)
return true;
else
return false;
}
void excg(int i,int j){
num[i]=num[j];
num[j]=num[i];
}
void display(){
for(int i=0;i<num.length;i++)
StdOut.println(num[i]);
}
public static void main (String[] arg){
Scanner in=new Scanner(System.in);
System.out.print("enter total num of the array");
int size=in.nextInt();
selection obj=new selection(size);
obj.enternum();
obj.sort();
}
}
when we enter the direct value of the size i.e size=5 then it is working but whenwe enter throughkey board then it is giving error aaray out of box .i am taking input through scanner class using nextInt() method