Java 用户输入后在输出中显示的数组

Java 用户输入后在输出中显示的数组,java,arrays,string,project,Java,Arrays,String,Project,我似乎不能让我的数组出现在输出中,这里是我的编码。有什么问题吗? 我希望我的“Jan”数组出现在我的菜单中,例如:Jan Expense,但只显示Expense。现在我在字符串monthChoice上有一个语法错误。请帮帮我。谢谢大家! import java.util.Scanner; public class Project { static String[] itemList = new String[10]; static int[] amountList = new int[10];

我似乎不能让我的数组出现在输出中,这里是我的编码。有什么问题吗? 我希望我的“Jan”数组出现在我的菜单中,例如:Jan Expense,但只显示Expense。现在我在字符串monthChoice上有一个语法错误。请帮帮我。谢谢大家!

import java.util.Scanner;

public class Project {
static String[] itemList = new String[10];
static int[] amountList = new int[10];
static int choice;

public static void main(String[] args) {

    {   Scanner input = new Scanner(System.in);
        System.out.println("***************Expenditure***************");
        System.out.println("1)Enter monthly expenses");
        System.out.println("2)Display detailed expenditure by month");
        System.out.println("3)Quick glance at monthly expenses");
        System.out.println("4)Exit");
        System.out.println("Please select your choice <1-3>:");
        choice = input.nextInt();


        switch (choice) {
        case 1:
            int count = 0;
            String[] monthsArray = { "", "Jan", "Feb", "Mar", "Apr", "May",
                    "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
            System.out.println("*******************************************");
            System.out.println("\t\t\t\t");
            System.out.print("Enter month <1 for Jan - 12 for Dec>:");
            int month = input.nextInt();
            for (int i=0; i < monthsArray.length; i++)
            String monthChoice = monthsArray[month - 1];
            System.out.println("-------------------------------------");
            System.out.println(monthChoice + "expenditure (max 10 items)");
这:

应该是:

String monthChoice = monthsArray[month];
因为第一个月是空的

另外,我不理解for循环,因为您甚至不使用I变量,也不需要多次重复该操作:

for (int i=0; i < monthsArray.length; i++)

考虑一下:用户输入数字1,然后将其分配给月份变量,因此现在月份=1。for循环中的第一行现在要求MonthArray[month-1],这是MonthArray[1-1],它会变成MonthArray[0]。MonthArray的第0个元素是空字符串。当您将此打印为MathSead时,只得到字符串的第二部分,因此看起来好像得到了不想要的结果。

如果月份=1,MathsStray[0 ] =正常。为什么在函数中间没有AO,为什么要放置空字符串?+ 1,特别是for for;我现在明白我的错误了,谢谢你的帮助。我刚开始学习编程,所以我想我还有很多东西要学。谢谢你的帮助。我终于可以继续为我的项目做其他的编程了。这些错误在早期很常见:请将答案标记为已接受。很高兴这有帮助。
for (int i=0; i < monthsArray.length; i++)