java - Java 支票簿平衡器
问题描述
我无法更正以下代码。它没有给我任何语法错误,但我知道它背后有一些逻辑代码,我无法指出并纠正它。
我还是编码新手,所以我必须从你的帮助中学习。谢谢!
这是我应该编写代码的问题:
Make a simple checkbook balancer that would input a sequence of
deposits (positive floating-point values) and
issuances (negative floating-point values) terminated by a 0.
It would output the transaction type, the amount and the running balance for each entry.
Assume the initial balance of 0. Ensure that the issued check won’t bounce!
import java.util.*;
import java.lang.*;
public class Checkbook{
public static void main (String[]args){
Scanner input = new Scanner(System.in);
float bal=0, amt=0;
char reply;
do{
System.out.print("Input Amount: ");
amt=input.nextInt();
if(amt>0){
bal+=amt;
System.out.print("\nAmount: " +amt);
System.out.print("\nTransaction Line: Deposit");
System.out.print("\nRunning Balance: " +bal);
;
}
else if(amt<0 ){
bal-=amt;
System.out.print("\nAmount: " +Math.abs(amt));
System.out.print("\nTransaction Line: Issuance");
System.out.print("\nRunning Balance: " +bal);
;
}
else
do{
System.out.println("Hello world!");
System.out.println("Again? [y/n]");
reply=input.next().charAt(0);
}while(reply!='n');
}while(bal!=0);
}
}
解决方案
推荐阅读
- javascript - 在 IIS 服务器 10 发布的 ASP.net 页面上显示为正方形的字体真棒图标
- android - 在 Expo 上出现错误'RNFirebase core module was not found native on Android'
- javascript - 当我在下面的代码中输入 jquery 时如何过滤我的列表?
- mysql - Mysql查询计算运行余额
- python - Linux 上的 psutil 显示没有 CPU 核心温度
- reactjs - 无法使用 XYZ 瓷砖居中地图
- batch-file - 批处理中链式 if 语句的问题
- python - 将字典类型转换为列表后如何使用for循环?
- flutter - 渲染后更新有状态的小部件变量?
- java - 从特定用户 ID Firebase 回收器适配器获取键值