import java.util.*;
public class StringInput
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
//int i=1;
//String name[]=new String[2];
System.out.println("Enter the String size");
int size= sc.nextInt();
String name[]=new String[size];
//String str=null;
size=name.length;
System.out.println("enter the strings");
for(int i=0;i<=size;i++)
{
name[i]=sc.nextLine();
}
System.out.println("String length = " +size);
for(int i=0;i<=size;i++)
{
System.out.println("String is " +name[i]);
//System.out.println("String is " +Arrays.asList(name));
}
}
}
Ausgabe:Wie das Array Inhalt anzeigen
die Größe String Geben Sie
die Saiten eingeben
asdf
asdasd
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 bei Array.StringInput.main (StringInput.java:22)
// Wie die gegebene Anordnung von Zeichenketten zur Ausgabe ??
'für (int i = 0; i
silentprogrammer
Lesen Sie weiter diese Frage http://StackOverflow.com/Questions/13102045/Skipping-nextLine-after-using-next-NextInt-oder-other-nextfoo-methods –