The reason you are getting 4 outputs is because you have 4 elements in the array,
for(String word : Words)
But you are printing the array itself, not the
String
element. Thus, Java is unable to print the array rather outputs the address where that object is being stored in the memory. You can fix that by changing the line of code that prints the words,
for(String word : Words)
{
System.out.println(word);
}
Like this, now the output would be the words in the array, not the array itself.
Complete code for this would be,
public class JavaArrays {
public static void main(String []args) {
String[] Words = new String[4];
Words[0] = "Android";
Words[1] = "Java";
Words[2] = "CSS";
Words[3] = "JavaScript";
for(String word : Words) {
System.out.println(word);
}
}
}
You can try this sample in your own IDE.