-1
public static void main(String[] args) {
    Scanner scan1 = new Scanner(System.in);
    int deposit = 0;
    String yesno = "";
        try 
    {
        System.out.println("Do you have an account already?");
        yesno = scan1.next();
        if(yesno == "no")
            throw new Exception(" ");            
        System.out.println(yesno);
        Calculate();


    } 
    catch (Exception e) 
    {
        System.out.println("HAHAHA");
    }
}
public void Calculate()
{
    System.out.println("Calculate");
}

The Calculate(); gives an error. How to fix this? C:\Users\MAC\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:48:

I'm trying to learn new things in java because last time, I was using JavaFX but I don't know how to use the Public void and how to call them here in Java.

Mac
  • 47
  • 7

2 Answers2

1

You can't call a non-static method from a static block of code.You have to declare Calculate static or create an object of the main class and call the method to it.

theVoid
  • 743
  • 4
  • 14
0

Create an instance of your main class and then call the calculate method:

If Test is your class name:

Test test = new Test();
test.Calculate();

Other solution is to make the Calculate function static:

 public static void Calculate() {
 // do something
 }
Chris623
  • 2,464
  • 1
  • 22
  • 30