• Post Reply Bookmark Topic Watch Topic
  • New Topic

Switch Statement  RSS feed

 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there! I am using a switch statement for my program which works like a charm but i was wondering, can i have 2 options in 1 case? This is what i have :


and it goes till "z" but i would like to know if i can somehow have the first case work for both "a" and "A"?!
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do:
or
Beware, toLowerCase() can act "strange" on some locales.
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:You can do:

Beware, toLowerCase() can act "strange" on some locales.[code=java]System.out.println("I".toLowerCase(new Locale("tr", "TR")));


Don't quite get what you mean by that!
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Locale object represents a specific geographical, political, or cultural region.
In different languages and regions "to lower case" operation might mean different things.

For example.
In Turkish language (represented by new Locale("tr", "TR") in the example) the lower case of I is ı and not i as one might except.

Suppose, one writes a code like this:... and the person from Turkey wants to execute it typing "I" for input.
What do they see?
Illegal choice...

Because their I was converted to ı which was not matched by any case.

I mentioned this because one must be aware of this behaviour when using "shortcuts" (as toLowerCase)
 
stelios papamichael
Ranch Hand
Posts: 93
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:A Locale object represents a specific geographical, political, or cultural region.
In different languages and regions "to lower case" operation might mean different things.

For example.
In Turkish language (represented by new Locale("tr", "TR") in the example) the lower case of I is ı and not i as one might except.

Suppose, one writes a code like this:... and the person from Turkey wants to execute it typing "I" for input.
What do they see?
Illegal choice...

Because their I was converted to ı which was not matched by any case.

I mentioned this because one must be aware of this behaviour when using "shortcuts" (as toLowerCase)


I had no idea about such things wow.Thanks a ton, however i won't use this since my program will be used by me and my friend only and we both live in the same country.Despite all of this, this info is amazing thanks a lot!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!