• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

//question of round-up//

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a switch statement, the argument to the case( case(argument) )can be any variable which can fit within an int??
Ans:false, the case argument must be either an int literal, or an int-compatible variable which is a constant.
What's the meaning??I can't understand what it says??
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to Mughal, p. 137:


The type of the integral expression [for switch] must be char, byte, short or int. The case label values must be assignable to the type of the integral expression. In particular, the case label values must be in the range of the type of the integral expression. Note that the type of the case label cannot be boolean, long or floating-point.

 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The case argument must be either an int literal, or an int-compatible variable which is a constant.

The case argument must be a constant. It can be an int literal ( like 1 , 2 , 3 ... ) or it can be a variable which has been declared as a constant ( like final int myCase = 2 ).

If it is a variable, it must be "final" (constant) and it must fit into an int (it can be a byte, short, char, or int). A long, float, double or boolean won't compile.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The constant case expressions can be any expression that is assignable to the type of the switch expression.

Prints: v y w z
Note: 'd'-'a'=3, ~0=-1, 4&5=4.
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic