Java 实例 - 数组输出


以下实例演示了如何通过循环输出数组:

  1. /*
  2. author by shouce.ren
  3. 文件名:Main.java
  4. */
  5.  
  6. public class Welcome {
  7. public static void main(String[] args){
  8. String[] greeting = new String[3];
  9. greeting[0] = "This is the greeting";
  10. greeting[1] = "for all the readers from";
  11. greeting[2] = "Java Source .";
  12. for (int i = 0; i < greeting.length; i++){
  13. System.out.println(greeting[i]);
  14. }
  15. }
  16. }

以上代码运行输出结果为:

  1. This is the greeting
  2. For all the readers From
  3. Java source .