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 .