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

时间:2018-11-24 20:09:33

标签: java arrays

输出列出了从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();
   }
   }

1 个答案:

答案 0 :(得分:1)

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