英文:
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 <gameList.length; i ++)
System.out.print(gameList[i]+" ");
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论