Java 程序在我的程序开始时停止

Java 程序在我的程序开始时停止,java,Java,我是编程新手,我想知道我是否能得到一些帮助。我的程序在System.out.println(“要计算利息,我们需要三个值。第一个是利息的百分比。第二个是申请利息的时间。第三个是申请利息的金额。”)。我愿意接受任何建议。另外,请指出这个程序的其他错误。谢谢 import java.util.Scanner; public class Interest { double userInput; double interest; double time; do

我是编程新手,我想知道我是否能得到一些帮助。我的程序在
System.out.println(“要计算利息,我们需要三个值。第一个是利息的百分比。第二个是申请利息的时间。第三个是申请利息的金额。”)。我愿意接受任何建议。另外,请指出这个程序的其他错误。谢谢

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

    }

}

去掉所有多余的牙套;它们在
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)
publicstaticvoidmain(字符串[]args)
{
System.out.println(“要计算利息,我们需要三个值。第一个是利息的百分比。第二个是申请利息的时间。第三个是申请利息的金额。”);

//}您正在编写实例块,而在main方法中,您没有创建对象。实例块是在创建类的对象时执行的。如果要执行这些实例块,您应该在main方法中编写
YourClass myclass=new YourClass()
,当您运行main函数时,这些块在main()之外将被执行,或者您应该像@shmosel的示例一样在main方法中编写这些块。

对不起,我对编程很陌生,但如何让程序前进?第一条语句正在显示,但没有继续,但程序仍在运行。有什么建议吗?@DanielLonarkar它可能在等待输入。我给它输入,但它什么也没做。