| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1573 人关注过本帖
标题:我在这里只想调用方法的返回值,为什么总是调用了方法的结构体啊。
只看楼主 加入收藏
我有个梦想
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2017-1-21
结帖率:0
收藏
 问题点数:0 回复次数:1 
我在这里只想调用方法的返回值,为什么总是调用了方法的结构体啊。
代码如下
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
求大神指引
搜索更多相关主题的帖子: balance initial public double return 
2017-05-11 11:09
Apple_wx
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2017-5-11
收藏
得分:0 
回复 楼主 我有个梦想
你是不是哪里操作错误?
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
2017-05-11 15:59
快速回复:我在这里只想调用方法的返回值,为什么总是调用了方法的结构体啊。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015491 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved