ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
switch logic is available almost all types of programming language.
Code:
int type;
type = System.in.read();
switch(type) {
case 11:
switch(type2) {
case 21:
variable = "case 21";
case 22:
variable = "case 22";
break;
case 12:
variable = "case 2";
break;
}
My question is:
I would like to have DOUBLE switch(), I mean like second switch() inside each case like above code. Could you please show me a brief implementation/example ?
in the switch(type) , inside the bracket, what type of this variable can be?
as integers 11 and 12 mean the 11th and 12th ascii chars, and they are both control characters, cannot be entered.
as strings "11" and "12" can be entered but cannot be handled by System.in.read() (because it handles only single keypresses/chars)
see here: http://www.abbeyworkshop.com/howto/j...ine/index.html
"type could be char, short, int, long or enumerated."
Please show me a similar code example that the INPUT type is int
Quote:
Originally Posted by fhleung
What I want was type number 11, 12 on the keyboard.
It sounds like you want to input character strings like "11", "12" etc and then convert them to integers.
I'm not sure that Java's System.in class has methods that do this directly. However, the java.lang.Integer class has methods which will convert the input strings to integers.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.