2012-02-29 7 views
0

私はmethod1からFvalue1を取得し、mainメソッドに戻す方法を見つけるのに助けが必要です。メインメソッドに返品を戻すにはどうすればよいですか?

import java.util.*; 

public class FutureValues { 
    public static void main(String[] args) { 
     Scanner CONSOLE = new Scanner(System.in); 

     System.out.print("present value : "); 
     double Pvalue = CONSOLE.nextDouble(); 
     System.out.print("interest rate : "); 
     double Interest = CONSOLE.nextDouble(); 
     System.out.print("number of years : "); 
     double Years = CONSOLE.nextDouble(); 

     method1(Pvalue, Interest, Years); 

     System.out.print("The future value using compound interest = " + Fvalue1); 

     return Fvalue1; 
    } 

    public static double method1(double Pvalue, double Interest, double Years) { 
     return Fvalue1 = Pvalue * Math.pow(1 + Interest/100, Years); 
    } 
} 

答えて

0

答えを間違って返し、呼び出し元関数で設定していません。これは動作するはずです:

import java.util.*; 

public class FutureValues { 

    public static void main(String[] args) { 
     Scanner CONSOLE = new Scanner(System.in); 

     System.out.print("present value : "); 
     double Pvalue = CONSOLE.nextDouble(); 
     System.out.print("interest rate : "); 
     double Interest = CONSOLE.nextDouble(); 
     System.out.print("number of years : "); 
     double Years = CONSOLE.nextDouble(); 

     double Fvalue1 = method1(Pvalue, Interest, Years); 

     System.out.print("The future value using compound interest = " + Fvalue1); 
    } 

    public static double method1(double Pvalue, double Interest, double Years) { 
     return Pvalue * Math.pow(1 + Interest/100, Years); 
    } 
} 

キーの変更があること:

double Fvalue1 = method1(Pvalue, Interest, Years); 

return Pvalue * Math.pow(1 + Interest/100, Years); 
+0

感謝を私は本当に立ち往生した:)私は助けることができる – user1239224

+0

うれしいです! – Developer

+0

ああ、私はあなたが置くものに入れて待っている "静的エラー:このクラスは静的な空のメインメソッドを受け入れるString []を持っていません。 – user1239224

関連する問題