내 100 대 숫자를 단어로 표시하려면 도움이 필요합니다. 예를 들어 116을 입력하면 내 프로그램은 1 백 16 대신 1 백 6을 출력합니다. 내가 입력 한 다른 모든 숫자는 십대 숫자를 제외하고 작동합니다.
코드에서 4 가지를 변경 합니다.
먼저:
입력 int
대신 사용double
int numInput = Integer.parseInt(br.readLine());//user inputs number
둘째:
int
사용중인 적절한 숫자 배치를 얻으려면 :
int hundredsDigit = (numInput % 1000) / 100;
int tensDigit = (numInput % 100) / 10;
int onesDigit = numInput % 10;
대신에:
double hundredsDigit=Math.floor((numInput%1000)/100);
double tensDigit = Math.floor((numInput % 100) / 10);
double onesDigit = numInput % 10;
제삼:
else
110-119 범위 의 조건은 100-999 (기술적으로 120-999 여야 함) 이전이어야합니다.
네번째:
십대 메서드는 원래 numInput을 매개 변수로 사용합니다.
당신이 취해야 onesDigit
할 것은 그것이 어떤 "십대"인지 결정하는 것입니다
따라서 다음과 같은 호출이어야합니다.
teens(onesDigit);
이 호출 은 [10-19] 조건 및 [110-119] 조건에서 변경 되어야합니다.
그리고 십대의 새로운 방법은 다음과 같아야합니다.
public static void teens(int onesDigit) {
if (onesDigit == 0) {
System.out.print("Ten ");
}
if (onesDigit == 1) {
System.out.print("Eleven ");
}
if (onesDigit == 2) {
System.out.print("Twelve ");
}
if (onesDigit == 3) {
System.out.print("Thirteen ");
}
if (onesDigit == 4) {
System.out.print("Fourteen ");
}
if (onesDigit == 5) {
System.out.print("Fifteen ");
}
if (onesDigit == 6) {
System.out.print("Sixteen ");
}
if (onesDigit == 7) {
System.out.print("Seventeen ");
}
if (onesDigit == 8) {
System.out.print("Eighteen ");
}
if (onesDigit == 9) {
System.out.print("Nineteen ");
}
}//closes teens method
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다