2016-07-01 10 views
-3

私はプログラミングが初めてで、何か助けてもらえないかと思っていました。私のプログラムの実行は、System.out.println("To calculate interest, we need three values. the first is the percent of interest. The second is the time the interest has to be applied for. The third is the amount of money the interest is being applied on.");になります。私はどんな提案にも開放的です。また、このプログラムに何か間違っていることを指摘してください。ありがとう!プログラムがプログラムの初めに停止する

import java.util.Scanner; 

public class Interest 

{ 

    double userInput; 

    double interest; 

    double time; 

    double amount; 

    double answer; 

    Scanner myScanner = new Scanner(System.in); 

    public static void main(String[] args) 

    { 

     System.out.println("To calculate interest, we need three values. the first is the percent of interest. The second is the time the interest has to be applied for. The third is the amount of money the interest is being applied on."); 

    } 

    { 

     System.out.println("Please enter your percent of interest in a decimal format: "); 

     userInput = myScanner.nextDouble(); 



     if(myScanner.hasNextDouble()) 

      { 

       interest = userInput; 

      } 

      else 

      { 

       System.out.println("Please enter a integer for your percent of interest."); 

      } 

    } 

    { 

     System.out.println("Please enter the time the interest is applied for: "); 

     userInput = myScanner.nextDouble(); 



     if(myScanner.hasNextDouble()) 

      { 

       time = userInput; 

      } 

      else 

      { 

       System.out.println("Please enter an integer for the time the interest is applied for."); 

      } 

    } 

    { 

     System.out.println("Please enter your amount of money that the interest is applied to: "); 

     userInput = myScanner.nextDouble(); 



     if(myScanner.hasNextDouble()) 

      { 

       amount = userInput; 

      } 

      else 

      { 

       System.out.println("Please enter an integer for the amount of money that the interest is applied to."); 

      } 

    } 

    { 

     answer = (amount * interest * time); 

    } 

    { 

     System.out.println("Your interest is $" + answer + "."); 

     System.out.println("Your total payment is $" + (answer + amount) + "."); 

    } 

} 

答えて

0

すべての余分な中かっこを取り除きます。彼らはあなたのmainメソッド外です。

public static void main(String[] args) 

{ 

    System.out.println("To calculate interest, we need three values. the first is the percent of interest. The second is the time the interest has to be applied for. The third is the amount of money the interest is being applied on."); 

// } <-- remove 

// { <-- remove 

    System.out.println("Please enter your percent of interest in a decimal format: "); 

// -----SKIP----- 

// } <-- remove 

// { <-- remove 
    System.out.println("Your interest is $" + answer + "."); 

    System.out.println("Your total payment is $" + (answer + amount) + "."); 
} // leave this here (end of method) 
+0

申し訳ありませんが私はプログラミングに本当に新しいですが、私はどのようにプログラムを進めるために得るのですか?最初のステートメントは表示されていますが、進行中ではありませんが、プログラムはまだ実行されています。何かアドバイス? –

+0

@DanielLonarkarおそらく入力待ちです。 – shmosel

+0

私はそれを入力しますが、何もしません。 –

0

インスタンスブロックを書いているし、mainメソッドでは、あなたはあなたがあなたのメインでYourClass myclass = new YourClass()を記述する必要があり、それらのインスタンスのブロックを実行したいclass.ifのオブジェクトを作成するときに、オブジェクトcreation.instanceブロックが実行されたことはありませんでしたmain関数を実行すると、main()の外側にあるブロックが実行されます。そうでない場合は、@ shmoselの例のようにmainメソッドにこれらのブロックを書き込む必要があります。

関連する問題