0

これにより、addAccountメソッドを呼び出そうとすると、呼び出そうとした行に.classが必要であるというエラーが発生します。
私は、addAccount2つのパラメーターを受け入れるというメソッドを作成することになっている割り当てを実行しようとしています。accountNameそしてaccountBalance、パラメータをaccountArray

import java.util.*;
public class bank
{
    public static void main(String[]args)
    {
        Scanner sc = new Scanner(System.in);
        int choice = 0;
        int accountNo = 0;
        double accountBal = 0;
        int[] accountNoArray = new int[20];
        int[] accountBalArray = new int[20];
        displayMenu();
        System.out.print("Please Enter Your Choice: ");
        choice = sc.nextInt();
        if(choice == 1)
        {
        System.out.print("Please Enter NRIC number: ");
        accountNo = sc.nextInt();
        System.out.print("Please Enter Account Balance: ");
        accountBal = sc.nextInt();
        }
        public static void displayMenu()
        {
        System.out.println("Menu");
        System.out.println("1. Add an account");
        System.out.println("2.Search an account with the given account number");
        System.out.println("3.Display accounts below the given balance");
        System.out.println("4.Exit");
        }
        public static void addAccount(int accountNo,double accountBal)
        {

        }
}
4

3 に答える 3

3

displayMenu メソッドの定義の前に右中括弧がありません。次のバージョンは構文的に正しいです。

public class Bank {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int choice = 0;
        int accountNo = 0;
        double accountBal = 0;
        int[] accountNoArray = new int[20];
        int[] accountBalArray = new int[20];
        displayMenu();
        System.out.print("Please Enter Your Choice: ");
        choice = sc.nextInt();
        if (choice == 1) {
            System.out.print("Please Enter NRIC number: ");
            accountNo = sc.nextInt();
            System.out.print("Please Enter Account Balance: ");
            accountBal = sc.nextInt();
        }
    }

    public static void displayMenu() {
        System.out.println("Menu");
        System.out.println("1. Add an account");
        System.out.println("2.Search an account with the given account number");
        System.out.println("3.Display accounts below the given balance");
        System.out.println("4.Exit");
    }

    public static void addAccount(int accountNo, double accountBal) {

    }
}
于 2012-08-18T06:21:13.260 に答える
0

メソッドの呼び出し時にパラメーターの型を指定しないでください。

ここにエラーがあります:

case 1 : addAccount(int accountNo,double accountBal);

それは違いない:

case 1 : addAccount(accountNo,accountBal); break;
于 2012-08-18T07:41:25.533 に答える
0

static と宣言したので、呼び出しの前にクラス名を追加する必要があります

bank.addAccount(int accountNo,double accountBal);

型宣言の代わりに、パラメーターを使用して呼び出す必要があります。

bank.addAccount(accountNo,accountBal);
于 2012-08-18T07:42:34.613 に答える