Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Control for String  RSS feed

 
umut uzumcu
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

while((name.equals("")) || (course.equals("")))
{


name=JOptionPane.showInputDialog("Please enter student name "+ (k+1));
course=JOptionPane.showInputDialog("Please enter student course "+ (k+1));

}

How can I check the entered informtion if its String or not?
User enters information and it should be String how can i put control so that they cant enter anything else than String?
[ January 17, 2007: Message edited by: umut uzumcu ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing to consider is what constitutes valid input for your field? Would any of these be invalid?

Garrett
Garrett M Rowe
Garrett M. Rowe
Mr. Rowe
Garrett "the Animal" Rowe
gmr1960@myplace.org
GMR

Once you have settled on a set of rules, you need to code a method or a class that can take an input String and send you a "message" letting you know whether the String was valid or not. The "message" is generally a boolean return value, however it could be anything including a custom Object of some sort. Then you could do something like this:


}
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or move the tests into the while condition ...

This may be one of the very few places I'd like a do-while

Almost enough to make me miss COBOL perform-until.
[ January 17, 2007: Message edited by: Stan James ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!