穏やかで、これは私の初めてのことです。 :)基本的な銀行プログラムはdoループを無限に通過しています。私は間違って何をしていますか?
ここではダメージがあります:私はそれまで、私はうまくやっている非主要なプログラミングクラスです。しかし、その後、この怪物があった。このプロジェクトは単純な銀行プログラムですが、私は永遠にループするか、知られていないcharを持つ問題があります。
ここまでは私のコードです。もしそれが奇妙に見えたり、非効率的なやり方で行われたりするのは、それがクラスが私を連れてきた場所だからです。参考までに、次のクラスは配列(アイデアなし)についてです。
import java.text.*;
import java.util.*;
/**
* Bank program
*
* @********
* @3
*/
public class Proj3also
{
public static void main(String []args)
{
DecimalFormat df = new DecimalFormat("#0.00");
System.out.println("Welcome to the banking program.");
System.out.println("");
Scanner s = new Scanner(System.in);
System.out.print("Please enter your starting balance: ");
double bal = Double.parseDouble(s.nextLine());
System.out.print("");
double deposit;
double withdraw;
do
{ System.out.print("Enter (d)eposit, (w)ithdraw, (b)alance check, or (q)uit: ");
if (input == 'b' || input == 'B')
{
System.out.print("Your balance is: $");
System.out.println(df.format(bal));
System.out.println("");
}
else if (input == 'd' || input == 'D')
{
System.out.print("Enter the amount to deposit: ");
deposit = Double.parseDouble(s.nextLine());
bal = bal + deposit;
System.out.println("");
}
else if (input == 'q' || input == 'Q')
{
System.out.print("");
System.out.print("Exiting the banking program. Goodbye!");
}
else if (input == 'w' || input == 'W')
{
System.out.print("Enter the amount to withdraw: ");
withdraw = Double.parseDouble(s.nextLine());
if (withdraw > bal)
{
System.out.println("Transaction failed. Withdraw amount cannot exceed balance.");
System.out.println("");
}
else
{
bal = bal - withdraw;
System.out.println("");
}
}
}
while(input != 'q' || input != 'Q');
}
}
これは、インストラクターのプログラムは次のようになります。任意の助けをいただければ幸いです
http://i15.photobucket.com/albums/a376/decode_6/project3.png
!その条件が常に真であるため、
あなたは実際にどこで 'input'を読んでいますか? 'input = s.nextLine()'のようなものです。 – jv42