나는 나 자신에게 자바를 가르치려고 노력하고 내가 가진 책에 두 장 약간의 딸꾹질 실행 해요 : P를이 운동 중 하나입니다 :자바 환율 교단 문제
는 "그 계산하는 클래스를 작성 입력 된 달러의 통화 단위를 20, 10, 5, 1로 변환하여 표시합니다. "
지금까지 코딩에 대한 지식이 4 시간 이상 이었으므로이 질문에 대답하는 것이 너무 단순하지 않다고 생각합니다. 나는이 모든 것을 작성하는 훨씬 더 효율적인 방법이있을 것이라고 확신하지만, 내 질문은 사용자가 "예"라고 응답하면 전체를 종료 할 수 있고 "아니오"라고 대답하면 수정 된 버전으로 계속 진행할 수있다.
또한 자바를 배우는 데 도움이되는 조언이나 안내는 많은 도움이됩니다. 모든이
import javax.swing.JOptionPane;
public class Dollars
{
public static void main(String[] args)
{
String totalDollarsString;
int totalDollars;
totalDollarsString = JOptionPane.showInputDialog(null, "Enter amount to be converted", "Denomination Conversion", JOptionPane.INFORMATION_MESSAGE);
totalDollars = Integer.parseInt(totalDollarsString);
int twenties = totalDollars/20;
int remainderTwenty = (totalDollars % 20);
int tens = remainderTwenty/10;
int remainderTen = (totalDollars % 10);
int fives = remainderTen/5;
int remainderFive = (totalDollars % 5);
int ones = remainderFive/1;
JOptionPane.showMessageDialog(null, "Total Entered is $" + totalDollarsString + "\n" + "\nTwenty Dollar Bills: " + twenties + "\nTen Dollar Bills: " + tens + "\nFive Dollar Bills: " + fives + "\nOne Dollar Bills: " + ones);
int selection;
boolean isYes, isNo;
selection = JOptionPane.showConfirmDialog(null,
"Is this how you wanted the total broken down?", "Select an Option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
isYes = (selection == JOptionPane.YES_OPTION);
JOptionPane.showMessageDialog(null, "You responded " + isYes + "\nThanks for your response!");
isNo = (selection == JOptionPane.NO_OPTION);
int twenties2 = totalDollars/20;
int tens2 = totalDollars/10;
int fives2 = totalDollars/5;
int ones2 = totalDollars/1;
JOptionPane.showMessageDialog(null, "Total Entered is $" + totalDollarsString + "\n" + "\nTwenty Dollar Bills: " + twenties2 + "\nTen Dollar Bills: " + tens2 + "\nFive Dollar Bills: " + fives2 + "\nOne Dollar Bills: " + ones2);
}
}
답변 해 주셔서 감사합니다. 그것은 내가 이것을 완벽하게 끝내는 것을 도왔습니다 : D – user1761914