目次
if ステートメントで成功した金額ステートメントを出力する
質問内容
javaでatmプログラムを作りました。全体的に見て、うまくいきます。ただし、ユーザーが正常に貯蓄および小切手の金額を入力したときに、「制限を超えました」と表示されるようにしようとしています。これを行うには if ステートメントを使用します。ただし、「制限を超えました」というメッセージが表示されるかどうかはわかりません。 Javaを学ぶのは初めてなので、よろしくお願いします。
package atm; import java.util.Scanner; public class atm { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int checking = 1000, savings = 5000, withdrawal = 0, deposit = 0; System.out.println("======================"); System.out.println("Welcome to Sound Bank!"); System.out.println("======================"); while (true) { System.out.println("Please select which options: \n (C)Checking Balance \n (S)Savings"); String choice1 = cin.nextLine(); System.out.println("Please select of the following: "); System.out.println("(D)Deposit \n (W)Withdrawal \n (B)Check Balance \n (E)Exit"); String choice2 = cin.nextLine(); switch(choice2.toUpperCase()) { case "D": if (choice1.equalsIgnoreCase("C")) { System.out.println("Enter your deposit amount:"); double num = cin.nextDouble(); double total = checking + num; System.out.println("You entered" + num); System.out.println("You have" + total); if(num > checking) { System.out.println("You are over the limit."); } } else if (choice1.equalsIgnoreCase("S")) { System.out.println("Enter your deposit amount"); double num1 = cin.nextDouble(); double total1 = savings + num1; System.out.println("You entered" + num1); System.out.println("You have" + total1); if(num1 > savings) { System.out.println("You are over the limit."); } } break; case "W": if (choice1.equalsIgnoreCase("C")) { System.out.println("Enter your withdrawal amount:"); double w = cin.nextDouble(); double total2 = checking - w; System.out.println("You entered" + w); System.out.println("You have" + total2); if(w > checking) { System.out.println("You are over the limit."); } } else if (choice1.equalsIgnoreCase("S")) { System.out.println("Enter your withdrawal amount:"); double w2 = cin.nextDouble(); double total3 = cin.nextDouble(); System.out.println("You entered " + w2); System.out.println("You have" + total3); if(w2 > savings) { System.out.println("You are over the limit."); } } break; case "B": if (choice1.equalsIgnoreCase("C")) { double t1 = (checking + deposit) - withdrawal; System.out.println("Your total amount is:" + t1); } else if (choice1.equalsIgnoreCase("S")) { double t2 = (savings + deposit) - withdrawal; System.out.println("Your total amount is:" + t2); } break; case "E": System.exit(0); break; } } } }
ログイン後にコピー
正解
質問はあまり明確ではありません。しかし、あなたの問題は解決されたと思います
double w2 = cin.nextDouble();
double Total3 = cin.nextDouble();
期待どおりに動作するはずです。
以上がif ステートメントで成功した金額ステートメントを出力するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事
アサシンのクリードシャドウズ:シーシェルリドルソリューション
1 か月前
By DDD
Windows11 KB5054979の新しいものと更新の問題を修正する方法
3週間前
By DDD
Atomfallのクレーンコントロールキーカードを見つける場所
4週間前
By DDD
KB5055523を修正する方法Windows 11にインストールできませんか?
2週間前
By DDD
Inzoi:学校と大学への応募方法
3週間前
By DDD

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック
Gmailメールのログイン入り口はどこですか?
7747
15


Java チュートリアル
1643
14


CakePHP チュートリアル
1397
52


Laravel チュートリアル
1291
25


PHP チュートリアル
1234
29

