gpt4 book ai didi

java - 列表的输出从 0 开始,而不是 1

转载 作者:行者123 更新时间:2023-12-02 10:33:35 26 4
gpt4 key购买 nike

输出列出了从 0 而不是 1 开始的电影。类名称并不是真正的“Newmovies”,我只是更改了名称。这是我的代码:

 import java.util.Scanner;
public class NewMovies
{
private final String[] MOVIES = {"Spiderman", "Batman", "Black Panther",
"Hangover", "Avengers", "Robin hood", "Underworld"};
private final double[] COSTS = {5, 10, 13, 15, 8, 12, 6};
private Scanner sc;
public void NewMovies() {
}
private void start() {
sc = new Scanner(System.in);
for (int i = 0; i < 7; i++) {
System.out.println(i + 0 + ". " + MOVIES[i]);
}
System.out.println("Select number of the movie from list: ");
int num = sc.nextInt();
System.out.println("Enter number of days: ");
int day = sc.nextInt();
System.out.println("Total cost fo sale = " + COSTS[num] * day);
}
public static void main(String args[]) {
NewMovies odmh = new NewMovies();
odmh.start();
}
}

最佳答案

应该是:System.out.println((i + 1) + ". "+ MOVIES[i]);

关于java - 列表的输出从 0 开始,而不是 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53461942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com