Advertise Here

Author Topic: [JavaTutorial] Switch Statements  (Read 3358 times)

0 Members and 1 Guest are viewing this topic.

Offline Marsada

  • SMF For Free Newbie
  • *
  • Posts: 4
  • Java Assistant
    • View Profile

  • Total Badges: 9
    Badges: (View All)
    Topic Starter Combination Level 2 Level 1 First Post
[JavaTutorial] Switch Statements
« on: February 09, 2009, 07:57:56 pm »
[JavaTutorial] Switch Statements

Make a new java file and name it MySwitch.java
Code: [Select]
//1.
public class MySwitch {
//2.
int switch1 = 1;
//3.
public void SwitchMethod(int switcho) {
//4.
switch(switcho) {
//5.
case 1:
//6.
System.out.println("Switch1=" +switch1);
//7.
break;
//8.
}
}
}


Line1:The name of the class.
Line2:Declaring and setting the values of the ints.
Line3:Creating the method for the statement.(int switcho) this provides the additional help.If you dont have a declared statement here, the switch will not respond.
Line4: The switch statement and the declared int.
Line5:Case 1.Switch statements always start with cases, the other way is if and else statements.
Line6:The execution or plan you want to set, for example if this method is runned, it will show System.out.println(Basically it will print in the declared int set, or whatever you put in there.Its just like a speech bar.
Line7:The break ends the case.And allows the next case to come.
Line8:Line 8 ends the method and the class.

Thats about it for this tutorial.Thank you for visiting it.

/*
*Copyright Marsada(c)
*(c)2007-2009(c)
*/
« Last Edit: February 09, 2009, 08:01:19 pm by Marsada »

 

Related Topics

  Subject / Started by Replies Last post
14 Replies
3893 Views
Last post February 25, 2007, 12:08:08 pm
by Laugh-nd-kid
2 Replies
1515 Views
Last post March 31, 2007, 09:59:55 am
by Pietra Atomica
1 Replies
5363 Views
Last post February 09, 2009, 04:51:01 pm
by Colette Brunel
0 Replies
3651 Views
Last post February 09, 2009, 08:35:49 pm
by Marsada
1 Replies
4521 Views
Last post August 26, 2009, 05:32:18 pm
by Games