本文介绍了试图为银行应用程序调用一个名为addAccount的方法,但它一直给我.class是预期的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试调用 addAccount
方法时,这会让我出错。在我尝试调用它的行上预计会出现.class。
我正在尝试进行一项任务,我应该创建一个名为 addAccount
的方法,它接受两个参数; accountName
和 accountBalance
并将参数放入 accountArray
This has been giving me error when I try to invoke the addAccount
method saying .class is expected on the line where I try to invoke it.
I am trying to do an assignment whereby I am supposed to create a method called addAccount
that accepts two parameters; accountName
and accountBalance
and put the parameters into an 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)
{
}
}
推荐答案
在displayMenu方法的定义之前,您缺少一个结束花括号。以下版本在语法上是正确的:
You are missing a closing curly bracket before the definition of the displayMenu method. The following version is syntactically correct:
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) {
}
}
这篇关于试图为银行应用程序调用一个名为addAccount的方法,但它一直给我.class是预期的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!