Java数组输出打印实例
如何编写让一个字符串数组到输出控制台?
解决方法
下面的例子演示了通过循环写入数组元素到输出控制台。
public class Welcome { public static void main(String[] args){ String[] greeting = new String[3]; greeting[0] = "This is the greeting"; greeting[1] = "for all the readers from"; greeting[2] = "Java Source ."; for (int i = 0; i < greeting.length; i++){ System.out.println(greeting[i]); } } }
结果
上面的代码示例将产生以下结果。
This is the greeting For all the readers From Java source .