Java - problema ordenamiento

 
Vista:

problema ordenamiento

Publicado por felipe (27 intervenciones) el 17/07/2008 21:24:37
Tengo un problema tengo que leer unos numeros y ordenarlos esto es lo que hecho. No se donde poner el while(hasNext) y no se cuando para de leerlos ¿cuando hay un espacio en blanco?

public class Santaclause {


public static void main(String[] args) throws Exception {
String sCadena;
int a[]= new int [100];
int y=0;
int num,i,j,x;
String pal;
Scanner in = new Scanner(System.in);
while (in.hasNext()){
for (y=0; y <= a.length; y++){
pal= in.next();
num= Integer.parseInt(pal);
a[y]= num;
}
}
for (i=1; i<=a.length;i++){
x = a[i];
j = i - 1;
while ((j>-1) && (a[j]>x)) {
a[j+1] = a[j];
j = j - 1;
}
a[j+1] = x;
}

for (y=0; y<=a.length; y++)
System.out.println(a[y]);
}

}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder