| JavaTutorial#4 Switch statements--fun :D | |
|
|
Author | Message |
---|
Zachy Addicted Cookie
Posts : 322 Points : 5747 Join date : 2009-07-12 Age : 32 Location : USA
| Subject: JavaTutorial#4 Switch statements--fun :D Fri Aug 14, 2009 9:29 pm | |
| Okay. I assume you've read and understand the topic i posted about what you need to do before you even attempt any of my tutorials. If you havent, Please read it here so i dont have to worry about useless errors -_- ______________________________________________________________________ I want to get one more done before i go to bed. So here it goes-- We start out naming our class and typing that long line of random words lawl. - Code:
-
class SwitchStatTut { public static void main(String[] args) { From here, we start out by declaring our initial day number. For this it will be 3 - Code:
-
int day = 3; Now, we initiate our switch statement. - Code:
-
switch (day) { Always put your variable name in the parenthesis, If you were to declare your variable like int country = 4;, you'd put switch (country). now we start the cases, This is where the numbers come in. Just in this tutorial, I'm going to have the cases--Days, 1=sunday, 2=mondy, 3=tuesday, 4=wednesday, 5=thursday, 6=friday, 7=saturday. - Code:
-
case 1: System.out.println("Sunday"); break; case 2: System.out.println("Monday"); break; case 3: System.out.println("Tuesday"); break; case 4: System.out.println("Wednesday"); break; case 5: System.out.println("Thursday"); break; case 6: System.out.println("Friday"); break; case 7: System.out.println("Saturday"); break; The break; means if that is what the case is, to immediately stop. The reason we can use this here, is because we have System.out.println before, so it will print the the day when you run it. So, Now you should have. - Code:
-
class SwitchStatTut { public static void main(String[] args) {
int day = 3; switch (day) { case 1: System.out.println("Sunday"); break; case 2: System.out.println("Monday"); break; case 3: System.out.println("Tuesday"); break; case 4: System.out.println("Wednesday"); break; case 5: System.out.println("Thursday"); break; case 6: System.out.println("Friday"); break; case 7: System.out.println("Saturday"); break; Just close all your brackets and you're done, You can change the number in int day=3; to anything, as long as its 1-7. If you want, You can add default: System.out.println("invalid number"); break; at the end if you are afraid you're gonna put the wrong day number. Or if you wanna play around with it. Just remember to close your brackets. - Code:
-
class SwitchStatTut { public static void main(String[] args) {
int day = 8; switch (day) { case 1: System.out.println("Sunday"); break; case 2: System.out.println("Monday"); break; case 3: System.out.println("Tuesday"); break; case 4: System.out.println("Wednesday"); break; case 5: System.out.println("Thursday"); break; case 6: System.out.println("Friday"); break; case 7: System.out.println("Saturday"); break; default: System.out.println("invalid"); break; } } }
| |
|
| |
Admin #1 loler: [Owner]Henry
Posts : 1708 Points : 7147 Join date : 2009-07-04 Age : 28 Location : Southern California
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Thu Aug 27, 2009 11:56 pm | |
| | |
|
| |
[Admin]1337 Co-Owner~[Admin]1337
Posts : 1101 Points : 2147488532 Join date : 2009-07-07
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Fri Aug 28, 2009 1:24 pm | |
| | |
|
| |
Zachy Addicted Cookie
Posts : 322 Points : 5747 Join date : 2009-07-12 Age : 32 Location : USA
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Fri Aug 28, 2009 2:32 pm | |
| Lawl. Yeah. JavaJavaJavaJavaJava | |
|
| |
Perry Uber Chocolate Cookie
Posts : 599 Points : 5978 Join date : 2009-08-23 Age : 27 Location : Cali
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Tue Sep 01, 2009 9:37 pm | |
| lol henry u dont know much | |
|
| |
[Admin]1337 Co-Owner~[Admin]1337
Posts : 1101 Points : 2147488532 Join date : 2009-07-07
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Wed Sep 02, 2009 4:09 pm | |
| | |
|
| |
Perry Uber Chocolate Cookie
Posts : 599 Points : 5978 Join date : 2009-08-23 Age : 27 Location : Cali
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Wed Sep 02, 2009 4:13 pm | |
| lol henry is the nicest in the world | |
|
| |
Zachy Addicted Cookie
Posts : 322 Points : 5747 Join date : 2009-07-12 Age : 32 Location : USA
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Thu Sep 03, 2009 5:13 pm | |
| | |
|
| |
Perry Uber Chocolate Cookie
Posts : 599 Points : 5978 Join date : 2009-08-23 Age : 27 Location : Cali
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Thu Sep 03, 2009 9:05 pm | |
| u kno its true | |
|
| |
Zachy Addicted Cookie
Posts : 322 Points : 5747 Join date : 2009-07-12 Age : 32 Location : USA
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Fri Sep 04, 2009 3:24 pm | |
| | |
|
| |
Perry Uber Chocolate Cookie
Posts : 599 Points : 5978 Join date : 2009-08-23 Age : 27 Location : Cali
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Fri Sep 04, 2009 3:33 pm | |
| | |
|
| |
Nathan Target
Posts : 345 Points : 5752 Join date : 2009-07-30 Age : 30 Location : Washington
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Wed Sep 09, 2009 5:22 pm | |
| | |
|
| |
Zachy Addicted Cookie
Posts : 322 Points : 5747 Join date : 2009-07-12 Age : 32 Location : USA
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Wed Sep 09, 2009 6:13 pm | |
| Understand what?
o_O
I'll help if you tell me what you mean. | |
|
| |
Nathan Target
Posts : 345 Points : 5752 Join date : 2009-07-30 Age : 30 Location : Washington
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Wed Sep 09, 2009 6:15 pm | |
| nah dont i dont understand java stuff | |
|
| |
Zachy Addicted Cookie
Posts : 322 Points : 5747 Join date : 2009-07-12 Age : 32 Location : USA
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Wed Sep 09, 2009 6:16 pm | |
| Then you definatly dont belong in THIS topic. Go to the sticky :} (in this forum category thing) | |
|
| |
Nathan Target
Posts : 345 Points : 5752 Join date : 2009-07-30 Age : 30 Location : Washington
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Wed Sep 09, 2009 6:23 pm | |
| yes i dont i want post anything here anymore LOL | |
|
| |
Zachy Addicted Cookie
Posts : 322 Points : 5747 Join date : 2009-07-12 Age : 32 Location : USA
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Wed Sep 09, 2009 6:33 pm | |
| | |
|
| |
Admin #1 loler: [Owner]Henry
Posts : 1708 Points : 7147 Join date : 2009-07-04 Age : 28 Location : Southern California
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Sun Sep 13, 2009 1:39 pm | |
| wait, then what does this do? what do i save it as? | |
|
| |
Zachy Addicted Cookie
Posts : 322 Points : 5747 Join date : 2009-07-12 Age : 32 Location : USA
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Sun Sep 13, 2009 1:45 pm | |
| Well, You'll have to download Dr.Java. Like the sticky& tutorial # 1 says.
If you read those, YOu should be able to figure out on your own :p
But, If you still have trouble, YOu can ask me. | |
|
| |
Perry Uber Chocolate Cookie
Posts : 599 Points : 5978 Join date : 2009-08-23 Age : 27 Location : Cali
| Subject: Re: JavaTutorial#4 Switch statements--fun :D Mon Sep 21, 2009 7:36 pm | |
| hey can u help me make a server? o.o non hamachi | |
|
| |
Sponsored content
| Subject: Re: JavaTutorial#4 Switch statements--fun :D | |
| |
|
| |
| JavaTutorial#4 Switch statements--fun :D | |
|