首页 > 解决方案 > 我的 do 语句中的缩进出错

问题描述

所以我在do声明的缩进方面遇到了麻烦。缩进是否会有所不同,因为我检查了所有内容,并且通过它看起来很好?

public void menu()
{
    char option = '\0'; //This is intaillsing the character 
    Scanner scanner = new Scanner(System.in);

    System.out.println("Welcome" + customerName);
    System.out.println("\n");


    //These will be all the option that will be dispalyed for the user to choose an option 
    System.out.println("A. Check Balance");
    System.out.println("B. Deposit");
    System.out.println("C. Withdraw");
    System.out.println("D. Previous transaction");
    System.out.println("E. Deposit using checks");
    System.out.println("F. Exit");

    do //This is saying to do all of these statement 
    {
        System.out.println("Enter an option");
        option = scanner.next().charAt(0);
        System.out.println("\n");

        switch(option)
        {
        case 'A':
            System.out.println("Balance = " + balance);
        }
    }//This indentation is showing me error 
}

标签: javaformatting

解决方案


Java 在循环结构中没有语义上有意义的空白。您缺少循环结构的一半。特别while (condition);do-while循环的。

do {
   // ...
} while (condition);

推荐阅读