打印数组中的所有字符串

huangapple go评论92阅读模式
英文:

Print all strings of array

问题

非常新于Java和编程一般 正在尝试弄清楚如何打印我的数组的内容

public class GameClass {
    public static void main(String args[]) {
        String [] gameList = new String [] {"使命召唤", "天际", "守望先锋", "侠盗猎车手", "恶魔城", "生化危机", "光环", "战地", "战争之地", "辐射"};
        System.out.println(gameList[]);
    }
}
英文:

Very new to Java and programming in general. trying to figure out how to print the contents of my array

public class GameClass {
    public static void main(String args[]) {
        String [] gameList = new String [] {"Call of Duty", "Skyrim", "Overwatch", "GTA", "Castlevania", "Resident Evil", "HALO", "Battlefield", "Gears of War", "Fallout"};
        System.out.println(gameList[]);
    }
}

答案1

得分: 1

你可以使用util包进行一行打印。

System.out.println(java.util.Arrays.toString(gameList));
英文:

You can use the util package for one line printing

System.out.println(java.util.Arrays.toString(gameList));

答案2

得分: 0

应该会起作用。

for (int i = 0; i < gameList.length; i++)
    System.out.print(gameList[i] + " ");
英文:

Should do the trick.

 for(int i = 0 ; i &lt;gameList.length; i ++)
     System.out.print(gameList[i]+&quot; &quot;);

答案3

得分: 0

只需迭代每个元素并打印:

for (String s : gameList) {
    System.out.println(s);
}
英文:

Just iterate each element and print:

for(String s : gameList){
    System.out.println(s);
}

答案4

得分: 0

你可以使用以下循环打印出游戏数组:

for(String game : gameList){
     System.out.println(game);
}

这会遍历游戏数组中的每个项目并将其打印出来。

英文:

You can print out your array of games by using the following loop:

for(String game : gameList){
     System.out.println(game);
}

This runs through each item in your gameList array and prints it.

huangapple
  • 本文由 发表于 2020年3月15日 22:47:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/60694111.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定