terminar de leer
Publicado por felipe (27 intervenciones) el 21/07/2008 18:07:15
Tengo un programa que ordena numeros los recibe por teclado pero no se como parar el hasNext ya que debe leer hasta que no hayan mas datos podrian ayudarme?
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]);
}
}
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
0