Jsp switch statement usage

Source: Internet
Author: User

The switch declaration allows you to select an option for running a set of statements, based on a code return value expression.

Switch (expression ){
Case value_1:

Statement (s );
Break;
Case value_2:
Statement (s );
Break;
  .
  .
  .
Case value_n:
Statement (s );
Break;
Default:
Statement (s );
}

Instance test

Public class mainclass {

Public static void main (string [] args ){
Int I = 1;
Switch (I ){
Case 1:
System. out. println ("one .");
Break;
Case 2:
System. out. println ("two .");
Break;
Case 3:
System. out. println ("three .");
Break;
Default:
System. out. println ("you did not enter a valid value .");
    }
  }


Method two characters

Public class mainclass {
 
Public static void main (string [] args ){
Char yesno = 'n ';

Switch (yesno ){
Case 'n ':
System. out. println ("no selected ");
Break;
Case 'Y ':
System. out. println ("yes selected ");
Break;
    }
  }
}

Method 3

Public class main {

Public static void main (string [] args ){
Int I = 0;
Switch (I ){

Case 0:
System. out. println ("I is 0 ");
Case 1:
System. out. println ("I is 1 ");
Case 2:
System. out. println ("I is 2 ");
Default:
System. out. println ("free flowing switch example! ");
    }
  }
}
/*
I is 0
I is 1
I is 2
Free flowing switch example!
*/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.