Topic: 请教判断语句 |
Print this page |
1.请教判断语句 | Copy to clipboard |
Posted by: jasonwing27 Posted on: 2005-09-16 20:44 小弟有个问题,想请各位高手解答. 如果要输入一个数字,只有输入的是数字才条件为真,那么我要是输入了一个字母.那么怎么判断它不是数字和符号呢? 同样要是输入字母才为真,那么怎么判断它不是数字和符号呢? 谢谢! |
2.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: why Posted on: 2005-09-16 22:11 1. check the string character by character. 2. look for a library that do (1) for you 3. use Integer.parseInt, Double.parseDouble, etc., catch and handle the exceptions 4. use Regular Expression, java.util.regex to match (overkilling it is) 5. ... |
3.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: 冷血无情 Posted on: 2005-09-16 22:44 通过这个 Integer.parseInt() 方法应该可以转为数字! |
4.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: jasonwing27 Posted on: 2005-09-17 00:50 我不是想转化为数字啊, |
5.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: jasonwing27 Posted on: 2005-09-17 00:53 好比用IF ELSE语句来判断我的输入 如果输入数字则为真, 输入字符则为假 该怎么写判断语句啊 |
6.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: why Posted on: 2005-09-17 03:17 boolean isDigit(char c) { return (c >= '0' && c <= '9'); } boolean isAlphabet(char c) { // consider English alphabets only return ( (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ); } |
7.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: jasonwing27 Posted on: 2005-09-17 11:38 那么输入10以上的数字呢 |
8.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: why Posted on: 2005-09-17 12:08 jasonwing27 wrote: Could you please do some thinking? Make good use of your brain or ... it will Read my first reply... if you don't know how to do so, study the basics, don't expect other to do all the work for you. |
9.Re:请教判断语句 [Re: why] | Copy to clipboard |
Posted by: ranchgirl Posted on: 2005-09-17 13:20 why wrote: Mr. Why I like what you are saying, and I said similar things all the time in the past. However, I finally found out It is absolutely useless. Borrow some words from this article here http://bbs.chinajavaworld.com/post/view?bid=18&id=464233&sty=1&tpg=1&age=-1 "一个人改变自己都那么难,你还想改变别人?” The best thing you can do to this kind of people is "IGNORE". Ignore the unreasonable questions, unreasonable requirements (such as post again in less than 30 minutes). Ignore the bad or meaningless titles... Ignore is one of the best and the most powerful tools on the Internet!!! Ignore will save your time, and angryness! Ignore will help on your health... ... ... Mr. Why, this is just a suggestion, I don't want to change you either... Hehehehe, ignore me is OK ... Please ignore.... Thanks! Sincerely Yours... |
10.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: bluecrystal Posted on: 2005-09-17 22:06 我认为楼主基本功不扎实 我觉得问什么问题也好,不要总是发问,也要懂得知道自己思考,并且尝试去解决问题。 why的第一个回答,基本上已经指明了解决问题的几种方式 |
11.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: panther Posted on: 2005-09-21 16:16 jasonwing27 wrote: why第一个帖子的意思,是一个字符一个字符的检查,当然不会出现10之类的东西了. |
12.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: axman Posted on: 2005-09-22 13:07 我也奇怪,楼主的水平低才能问的,这不奇怪,水平高了就用不着问了. 但奇怪的是这么多的答案竟然非常................ regx多么简单啊, 是否数字? \\d+ 是否字母 [a-z][A-Z] 这么简洁的方法竟然没有人用 |
13.Re:请教判断语句 [Re: axman] | Copy to clipboard |
Posted by: ranchgirl Posted on: 2005-09-22 13:47 axman wrote: Sorry, regex, not regx! Regular expression is simple and easy to certain kind of people. However, it is almost non-understandable to some other people. That is just a fact. |
14.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: ranchgirl Posted on: 2005-09-22 13:51 Simplely, people are just different!!! Don't say someone is stupid, he/she might be unbeatable smart on some other fields. Not everyone can be good programmer, that is just another fact. I sincerely think 楼主 should change his/her major now. Of course, it is up to him/her. Thanks! |
15.Re:请教判断语句 [Re: why] | Copy to clipboard |
Posted by: lnxjx Posted on: 2005-10-17 19:44 why wrote: isAlphabet这个方法在哪个类里啊?我在API里没找到啊? |
16.Re:请教判断语句 [Re: lnxjx] | Copy to clipboard |
Posted by: why Posted on: 2005-10-17 21:50 lnxjx wrote: Could you read? I define it... sigh... |
17.Re:请教判断语句 [Re: jasonwing27] | Copy to clipboard |
Posted by: ranchgirl Posted on: 2005-10-17 22:51 Hey, don't sigh, it deserves a laugh. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |