A fun MapleStory Private Server.
 
HomeHome  CalendarCalendar  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log in  

Share | 
 

 JavaTutorial#4 Switch statements--fun :D

View previous topic View next topic Go down 
AuthorMessage
Zachy
Addicted Cookie
avatar

Posts : 322
Points : 3287
Join date : 2009-07-12
Age : 25
Location : USA

PostSubject: 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;
        }
    }
}
Back to top Go down
View user profile
Admin
#1 loler: [Owner]Henry
#1 loler: [Owner]Henry
avatar

Posts : 1708
Points : 4687
Join date : 2009-07-04
Age : 21
Location : Southern California

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

umm, what is this?

_________________
InGame name: [Owner]Henry ̿̿ ̿̿ ̿ ̿̿̿'\̵͇̿̿\

Made by Smexyx3 or Iloveyou or [gm]aly:) or Bunny. Man, she's changing her IGN a lot...
My first maple animation XD
Back to top Go down
View user profile http://lucidityms.forumotion.net
[Admin]1337
Co-Owner~[Admin]1337
Co-Owner~[Admin]1337


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

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

@Henry, its Java code

_________________
Don't Edit/Delete/Move My Post/Topics

If you need help, email SmileyCookieMSHelp@gmail.com.

Learning C++/D3D
Back to top Go down
View user profile
Zachy
Addicted Cookie
avatar

Posts : 322
Points : 3287
Join date : 2009-07-12
Age : 25
Location : USA

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

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


Posts : 599
Points : 3518
Join date : 2009-08-23
Age : 20
Location : Cali

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

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


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

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

Henry=Anti-Tech-Friendly

_________________
Don't Edit/Delete/Move My Post/Topics

If you need help, email SmileyCookieMSHelp@gmail.com.

Learning C++/D3D
Back to top Go down
View user profile
Perry
Uber Chocolate Cookie


Posts : 599
Points : 3518
Join date : 2009-08-23
Age : 20
Location : Cali

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

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

Posts : 322
Points : 3287
Join date : 2009-07-12
Age : 25
Location : USA

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

Lawl
Back to top Go down
View user profile
Perry
Uber Chocolate Cookie


Posts : 599
Points : 3518
Join date : 2009-08-23
Age : 20
Location : Cali

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

u kno its true Smile
Back to top Go down
View user profile
Zachy
Addicted Cookie
avatar

Posts : 322
Points : 3287
Join date : 2009-07-12
Age : 25
Location : USA

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

Water.
Back to top Go down
View user profile
Perry
Uber Chocolate Cookie


Posts : 599
Points : 3518
Join date : 2009-08-23
Age : 20
Location : Cali

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

lol random ^_^
Back to top Go down
View user profile
Nathan
Target
avatar

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

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

me dont understand O.O
Back to top Go down
View user profile
Zachy
Addicted Cookie
avatar

Posts : 322
Points : 3287
Join date : 2009-07-12
Age : 25
Location : USA

PostSubject: 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.
Back to top Go down
View user profile
Nathan
Target
avatar

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

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

nah dont i dont understand java stuff
Back to top Go down
View user profile
Zachy
Addicted Cookie
avatar

Posts : 322
Points : 3287
Join date : 2009-07-12
Age : 25
Location : USA

PostSubject: 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)
Back to top Go down
View user profile
Nathan
Target
avatar

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

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

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

Posts : 322
Points : 3287
Join date : 2009-07-12
Age : 25
Location : USA

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

lol
Back to top Go down
View user profile
Admin
#1 loler: [Owner]Henry
#1 loler: [Owner]Henry
avatar

Posts : 1708
Points : 4687
Join date : 2009-07-04
Age : 21
Location : Southern California

PostSubject: 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?

_________________
InGame name: [Owner]Henry ̿̿ ̿̿ ̿ ̿̿̿'\̵͇̿̿\

Made by Smexyx3 or Iloveyou or [gm]aly:) or Bunny. Man, she's changing her IGN a lot...
My first maple animation XD
Back to top Go down
View user profile http://lucidityms.forumotion.net
Zachy
Addicted Cookie
avatar

Posts : 322
Points : 3287
Join date : 2009-07-12
Age : 25
Location : USA

PostSubject: 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.
Back to top Go down
View user profile
Perry
Uber Chocolate Cookie


Posts : 599
Points : 3518
Join date : 2009-08-23
Age : 20
Location : Cali

PostSubject: 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 Smile
Back to top Go down
View user profile
Sponsored content




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

Back to top Go down
 
JavaTutorial#4 Switch statements--fun :D
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» CLOSING STATEMENTS FROM THE FINAL 2
» DMR SWITCH
» automatic count up/down circuit just pressing a latch switch
» Long Sword vs Switch Axe?
» That one golden event dragon switch axe

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