Unable to get total amount

前端 未结 2 1895
挽巷
挽巷 2021-01-26 12:51

Hi guys I have fixed the initial problem but now its not adding up correctly. I am unsure what to do and where I have gone wrong. Any help would be appreciated.

import j

2条回答
  •  囚心锁ツ
    2021-01-26 13:50

    maybe you trying to do something like this:

    public int someMethod(){
        int childTotal; // here variable must be initialized before return
                        // like this int childTotal = 0;
            switch (option) {
                case 1:
                childTotal=(int) ((double) quantity*childCost) ;
                System.out.println("Total amount for child tickets: $" + childTotal);
                break;
            }
            ...
            return childTotal;
    }
    

    in this case you'll get an error, that variable must be initialized.

    Anyway you gave to few information about your problem. Maybe you can show what kind of answer you get from the system, stackTrace or something like that. Did you know about diference between initialize and declare?

提交回复
热议问题