문제

I have a home work. I was asked to make a program that will get zipcode from a user input. Then I'm gonna use the first digit only to determine the location. My instructor told me that the data type to be used is int. can you pls help me? thanks

도움이 되었습니까?

해결책

You're comparing characters with integers, so currently you're comparing them with the control characters U+0003 and U+0004 - you want to compare them with characters representing the digits:

if (zipCode.charAt(0) <= '3')
...
if (zipCode.charAt(0) >= '4')
    if (zipCode.charAt(0) <= '6')

(You might consider using a switch statement too...)

I've no idea whether this is correct in terms of what zip codes mean, but that's the immediate problem with your code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top