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

2021-05-13 18:31

阅读:409

标签: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


评论


亲,登录后才可以留言!