Soy un novato en Java, así que no bajes la calificación si esto te suena absolutamente tonto.
ok, ¿cómo ingreso esto usando un solo objeto de escáner?
5
Hola cómo estás
Bienvenido a mi mundo
6 7
para aquellos de ustedes que sugieren
scannerobj.nextInt->nextLine->nextLine->nextInt->nextInt,,,
fijate que no funciona!!!
Gracias
Solución del problema
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.printf("Please specify how many lines you want to enter: ");
String[] input = new String[in.nextInt()];
in.nextLine(); //consuming the <enter> from input above
for (int i = 0; i < input.length; i++) {
input[i] = in.nextLine();
}
System.out.printf("\nYour input:\n");
for (String s: input) {
System.out.println(s);
}
}
Ejemplo de ejecución:
Please specify how many lines you want to enter: 3
Line1
Line2
Line3
Your input:
Line1
Line2
Line3
No hay comentarios:
Publicar un comentario