我在这里只想调用方法的返回值,为什么总是调用了方法的结构体啊。
代码如下import java.util.Scanner;
public class Account{
static double balance;
public double addmoney(){
if(balance==0){
int initial = 0;
System.out.println("Your initial money is"+initial);
return 0;
}
else{
double money = balance * 1.2;
return money;
}
}
public double withdraw(){
System.out.println("Do you want to withdraw?");
System.out.println("Please entet yes or no");
String judge;
Scanner input2 = new Scanner(System.in);
judge = input2.next();
if(judge.equals("yes")){
System.out.println("Please enter the number you want to withdraw:");
double number;
Scanner input3 = new Scanner(System.in);
number = input3.nextDouble();
double money2 = addmoney();
double money3 = money2;
if(number<=money3){
System.out.println("Withdraw successfully!");
System.out.println("Withdraw cash is:"+number);
}
else{
System.out.println("Error");
money3 = money3-5;
System.out.println("Your present is cash "+money3);
}
return 0;
}
else{
System.out.println("Ending!");
return 0;
}
}
public static void main(String[] args){
Account test = new Account();
System.out.println("Please input your balance");
Scanner input = new Scanner(System.in);
balance = input.nextDouble();
test.addmoney();
test.withdraw();
}
}
运行结果如下:
C:\Users\Administrator\Desktop>java Account
Please input your balance
10
Your initial money is:10.0
Your present cash is:12.0
Do you want to withdraw?
Please entet yes or no
yes
Please enter the number you want to withdraw:
10
Your initial money is:10.0
Your present cash is:12.0
Withdraw successfully!
Withdraw cash is:10.0
求大神指引