SmileyCookieMS
Would you like to react to this message? Create an account in a few clicks or log in to continue.


A fun MapleStory Private Server.
 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log in  

 

 JavaTutorial#4 Switch statements--fun :D

Go down 
5 posters
AuthorMessage
Zachy
Addicted Cookie
Zachy


Posts : 322
Points : 5747
Join date : 2009-07-12
Age : 32
Location : USA

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyFri 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;
        }
    }
}
Back to top Go down
Admin
#1 loler: [Owner]Henry
#1 loler: [Owner]Henry
Admin


Posts : 1708
Points : 7147
Join date : 2009-07-04
Age : 28
Location : Southern California

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyThu Aug 27, 2009 11:56 pm

umm, what is this?
Back to top Go down
https://lucidityms.forumotion.net
[Admin]1337
Co-Owner~[Admin]1337
Co-Owner~[Admin]1337



Posts : 1101
Points : 2147488532
Join date : 2009-07-07

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyFri Aug 28, 2009 1:24 pm

@Henry, its Java code
Back to top Go down
Zachy
Addicted Cookie
Zachy


Posts : 322
Points : 5747
Join date : 2009-07-12
Age : 32
Location : USA

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyFri Aug 28, 2009 2:32 pm

Lawl. Yeah. JavaJavaJavaJavaJava
Back to top Go down
Perry
Uber Chocolate Cookie



Posts : 599
Points : 5978
Join date : 2009-08-23
Age : 27
Location : Cali

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyTue Sep 01, 2009 9:37 pm

lol henry u dont know much
Back to top Go down
[Admin]1337
Co-Owner~[Admin]1337
Co-Owner~[Admin]1337



Posts : 1101
Points : 2147488532
Join date : 2009-07-07

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyWed Sep 02, 2009 4:09 pm

Henry=Anti-Tech-Friendly
Back to top Go down
Perry
Uber Chocolate Cookie



Posts : 599
Points : 5978
Join date : 2009-08-23
Age : 27
Location : Cali

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyWed Sep 02, 2009 4:13 pm

lol henry is the nicest in the world Very Happy
Back to top Go down
Zachy
Addicted Cookie
Zachy


Posts : 322
Points : 5747
Join date : 2009-07-12
Age : 32
Location : USA

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyThu Sep 03, 2009 5:13 pm

Lawl
Back to top Go down
Perry
Uber Chocolate Cookie



Posts : 599
Points : 5978
Join date : 2009-08-23
Age : 27
Location : Cali

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyThu Sep 03, 2009 9:05 pm

u kno its true Smile
Back to top Go down
Zachy
Addicted Cookie
Zachy


Posts : 322
Points : 5747
Join date : 2009-07-12
Age : 32
Location : USA

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyFri Sep 04, 2009 3:24 pm

Water.
Back to top Go down
Perry
Uber Chocolate Cookie



Posts : 599
Points : 5978
Join date : 2009-08-23
Age : 27
Location : Cali

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyFri Sep 04, 2009 3:33 pm

lol random ^_^
Back to top Go down
Nathan
Target
Nathan


Posts : 345
Points : 5752
Join date : 2009-07-30
Age : 30
Location : Washington

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyWed Sep 09, 2009 5:22 pm

me dont understand O.O
Back to top Go down
Zachy
Addicted Cookie
Zachy


Posts : 322
Points : 5747
Join date : 2009-07-12
Age : 32
Location : USA

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyWed Sep 09, 2009 6:13 pm

Understand what?

o_O

I'll help if you tell me what you mean.
Back to top Go down
Nathan
Target
Nathan


Posts : 345
Points : 5752
Join date : 2009-07-30
Age : 30
Location : Washington

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyWed Sep 09, 2009 6:15 pm

nah dont i dont understand java stuff
Back to top Go down
Zachy
Addicted Cookie
Zachy


Posts : 322
Points : 5747
Join date : 2009-07-12
Age : 32
Location : USA

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyWed Sep 09, 2009 6:16 pm

Then you definatly dont belong in THIS topic. Go to the sticky :} (in this forum category thing)
Back to top Go down
Nathan
Target
Nathan


Posts : 345
Points : 5752
Join date : 2009-07-30
Age : 30
Location : Washington

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyWed Sep 09, 2009 6:23 pm

yes i dont i want post anything here anymore LOL
Back to top Go down
Zachy
Addicted Cookie
Zachy


Posts : 322
Points : 5747
Join date : 2009-07-12
Age : 32
Location : USA

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyWed Sep 09, 2009 6:33 pm

lol
Back to top Go down
Admin
#1 loler: [Owner]Henry
#1 loler: [Owner]Henry
Admin


Posts : 1708
Points : 7147
Join date : 2009-07-04
Age : 28
Location : Southern California

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptySun Sep 13, 2009 1:39 pm

wait, then what does this do? what do i save it as?
Back to top Go down
https://lucidityms.forumotion.net
Zachy
Addicted Cookie
Zachy


Posts : 322
Points : 5747
Join date : 2009-07-12
Age : 32
Location : USA

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptySun 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.
Back to top Go down
Perry
Uber Chocolate Cookie



Posts : 599
Points : 5978
Join date : 2009-08-23
Age : 27
Location : Cali

JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D EmptyMon Sep 21, 2009 7:36 pm

hey can u help me make a server? o.o non hamachi Smile
Back to top Go down
Sponsored content





JavaTutorial#4 Switch statements--fun :D Empty
PostSubject: Re: JavaTutorial#4 Switch statements--fun :D   JavaTutorial#4 Switch statements--fun :D Empty

Back to top Go down
 
JavaTutorial#4 Switch statements--fun :D
Back to top 
Page 1 of 1
 Similar topics
-
» JavaTutorial #3 If-Then and if-then-else statements :D
» First JavaTutorial#1! Making The IDE do something! "Hello World!"

Permissions in this forum:You cannot reply to topics in this forum
SmileyCookieMS :: Programming :: Java-
Jump to: