자바로 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();
대체됨
double w2 = cin.nextDouble();
double Total3 = 节省 - w2;
예상대로 작동해야 합니다.
위 내용은 if 문에 성공 금액 명세서를 인쇄합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

WebStorm Mac 버전
유용한 JavaScript 개발 도구

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

Dreamweaver Mac版
시각적 웹 개발 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.
