2014-12-23 57 views
-5

我收到方法名稱下的紅線,爲什麼發生這種情況?方法未運行

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

哪個方法命名? –

+0

如果你有紅線,這表明你有一個編譯時錯誤。請在你的文章中加入。閱讀http://tinyurl.com/stack-hints關於爲Stack Overflow寫一個好問題的建議。 –

+0

你在你的代碼中有幾個問題..方法'公共靜態double Deposit()'需要在你的* current *方法之外。你還需要在'String account_owner = input.nextLine();' – TheLostMind

回答

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"); 

     }} 
0

你很有方法中的一個方法 - public static double Deposit。這是無效的。

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"); 
}