我在方法名称下面有红线,为什么会发生这种情况?
Scanner input=new Scanner(System.in);
System.out.println("enter your account number");
int account_num= input.nextInt();
System.out.println("enter your name");
String account_owner=input.nextLine();
System.out.println("enter your account balance");
double current_balance=input.nextDouble();
System.out.println("enter 1 to deposit \nenter 2 to withdraw"
+"\nenter 3 to add interest value"
+"\nenter 4 to print all the information");
int option= input.nextInt();
if (option==1){
System.out.println("enter the amount of money to be depsit");
double Damount=input.nextDouble();
double a =Deposit(Damount,current_balance);
System.out.print(a);
public static double Deposit(double amount, double balance){
balance+=amount;
System.out.println("transction successful");
}}
答案 0 :(得分:1)
您使用方法声明了一个方法。而且您的存款方法没有返回值。但是你的方法声明的返回类型为double。
删除以下代码并在方法
的外面执行 public static double Deposit(double amount, double balance)
{
balance += amount;
System.out.println("transction successful");
return balance; // missing return type
}
而不是
if (option==1){
System.out.println("enter the amount of money to be depsit");
double Damount=input.nextDouble();
double a =Deposit(Damount,current_balance);
System.out.print(a);
public static double Deposit(double amount, double balance){
balance+=amount;
System.out.println("transction successful");
}}
答案 1 :(得分:0)
您在方法中有一个方法 - public static double Deposit
。那是无效的。
答案 2 :(得分:0)
您需要在方法中没有方法。
if (option==1) {
System.out.println("enter the amount of money to be depsit");
double Damount=input.nextDouble();
double a =Deposit(Damount,current_balance);
System.out.print(a);
} //end of if
} // end of method
public static double Deposit(double amount, double balance){
balance+=amount;
System.out.println("transction successful");
}