Java zipcode program [closed]

左心房为你撑大大i 提交于 2019-12-13 07:58:00

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/13657991/java-zipcode-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!