码迷,mamicode.com
首页 > 编程语言 > 详细

[JAVA]一维数组的创建, 初始化,访问修改数组元素,遍历数组

时间:2020-06-14 23:48:35      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:print   out   bsp   删除   nbsp   odi   元素   string   rgs   

 

方法一:

String[] words = new String[] {"precarious", "exiguous", "prodigious"}; //注意new String[] 这里的[]必须是空的

方法二:

String[] words = {"precarious", "exiguous", "prodigious"}; //可以把new String[]直接删除

方法三:

String[] words = new String[3];
        words[0] = "precarious";
        words[1] = "exiguous";
        words[2] = "prodigious";

 

 

public class a1d
{
    public static void main(String[] args)
    {
        // String[] words = new String[] {"precarious", "exiguous", "prodigious"}; //注意new String[] 这里的[]必须是空的
        String[] words = {"precarious", "exiguous", "prodigious"}; //可以把new String[]直接删除
        // String[] words = new String[3];
        // words[0] = "precarious";
        // words[1] = "exiguous";
        // words[2] = "prodigious";
        System.out.println(words[1] + " earnings"); //访问数组元素
        words[1] = "paucity"; //修改值
        for (String word : words)
        {
            System.out.println(word);
        }
    }
}

 

[JAVA]一维数组的创建, 初始化,访问修改数组元素,遍历数组

标签:print   out   bsp   删除   nbsp   odi   元素   string   rgs   

原文地址:https://www.cnblogs.com/profesor/p/13127476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!