Java Programming/Keywords/case
Appearance
From Wikibooks, open books for an open world
This is the current revision of this page, as edited by Dirk Hünniger (discuss | contribs) at 11:42, 28 June 2024 (preparing for pdf generation with LaTeX). The present address (URL) is a permanent link to this version.
Revision as of 11:42, 28 June 2024 by Dirk Hünniger (discuss | contribs) (preparing for pdf generation with LaTeX)
case
is a Java keyword.
This is part of the switch
statement, to find if the value passed to the switch statement matches a value followed by case.
For example:
Computer code
inti=3; switch(i){ case1: System.out.println("The number is 1."); break; case2: System.out.println("The number is 2."); break; case3: System.out.println("The number is 3.");// this line will print break; case4: System.out.println("The number is 4."); break; case5: System.out.println("The number is 5."); break; default: System.out.println("The number is not 1, 2, 3, 4, or 5."); }