Switch case tutorial in java

in #switchcase2 years ago

Hello fellow future programmers today I will share another program that you may know

<p dir="auto">This is the topic "Switch case "here you can choose any of the case that you input in your code .in the output .<br /> Input import java.util.Scanner;<br /> then Scanner day = new Scanner(System.in);<br /> then System.out.println("Enter a day in a week); <p dir="auto">For example in seven case in your code inside of the parentheses of switch is day in the case you can input number or Monday to Sunday then in system.out println you can say anything that you can the Monday and soon and soon the next system.out.println after the break . <p dir="auto">The difference of not using break in your switch your program will output all of the case in your switch even you input only one of them it because you don't have break .<br /> When you have a break after the system.out println your program will not show all the case in your program the only shown to your program is your input on the output. <p dir="auto">After all the cases in your program you can use default then input again the system.out print then you can say in the parentheses not valid day then if you type in output of your program that not in list of the case the machine languages will say not valid because in your default is not valid which I said that in your cases is not on the list so the machine languages will say not valid. <p dir="auto">Then don't forget too foot semicolon after the your System.out println.<br /> Here is the source code!!<br /> mport java.util.Scanner;<br /> public class Main{<br /> public static void main(String[]args) {<br /> Scanner scanner= new Scanner(System.in);<br /> System.out.print("Enter a day in a week:");<br /> String day= scanner.nextLine(); <pre><code>switch (day) { case "Monday": System.out.println("Monday is the first day of the week!"); break; case "Tuesday": System.out.println("Tuesday is the second day of the week!"); break; case "Wednesday": System.out.println("Wednesday is the third day of the week!"); break; case "Thursday": System.out.println("Thursday is the fourth day of the week!"); break; case "Friday": System.out.println("Friday is the fifth day of the week!"); break; case "Saturday": System.out.println("Saturday is the sixth day of the week!"); break; case "Sunday": System.out.println("Sunday is the seventh day of the week!"); break; } <p dir="auto">}<br /> }<br /> Here is the result 👇<br /> <img src="https://images.hive.blog/768x0/https://files.peakd.com/file/peakd-hive/catleen/23tbEiUnRTHy8tXUYKte49QG4rVHm3hCjBFymsLgSttNbuSjPgGVK4UTWh8qgRwVakEWw.png" alt="Screenshot_20221111-140644.png" srcset="https://images.hive.blog/768x0/https://files.peakd.com/file/peakd-hive/catleen/23tbEiUnRTHy8tXUYKte49QG4rVHm3hCjBFymsLgSttNbuSjPgGVK4UTWh8qgRwVakEWw.png 1x, https://images.hive.blog/1536x0/https://files.peakd.com/file/peakd-hive/catleen/23tbEiUnRTHy8tXUYKte49QG4rVHm3hCjBFymsLgSttNbuSjPgGVK4UTWh8qgRwVakEWw.png 2x" /> <p dir="auto"><img src="https://images.hive.blog/768x0/https://files.peakd.com/file/peakd-hive/catleen/23tkdTHzvZhHdhhvdiRyYZ8ZJZSq7JFDHXvinZF65W5iq2RodxMvtazvkcLm6pK1yxmXY.png" alt="Screenshot_20221111-140530.png" srcset="https://images.hive.blog/768x0/https://files.peakd.com/file/peakd-hive/catleen/23tkdTHzvZhHdhhvdiRyYZ8ZJZSq7JFDHXvinZF65W5iq2RodxMvtazvkcLm6pK1yxmXY.png 1x, https://images.hive.blog/1536x0/https://files.peakd.com/file/peakd-hive/catleen/23tkdTHzvZhHdhhvdiRyYZ8ZJZSq7JFDHXvinZF65W5iq2RodxMvtazvkcLm6pK1yxmXY.png 2x" /> <pre><code>Thank you for reading and I hope you learned something about my tutorial in java <p dir="auto">you can use in laptop netbeans in mobile jvdroid compiler!😍 <p dir="auto">before I and my blog I just want thanks to all of you for supporting my blog and if you have a question regarding to programming just comment and I answered that
Sort:  

Very good dear..

Thank you 😊 I hope you learned

I'm not into programming of some sort so I really find this tricky. It sounded too smart for me. Hahahaha!

!PIZZA

Owee maybe next time I will share better than that.thankyou

🍕 PIZZA !

I gifted $PIZZA slices here:
(2/5) @chichi18 tipped @catleen (x1)

Join us in Discord!

Congratulations @catleen! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@catleen/upvoted.png?202211111405" /><td>You received more than 500 upvotes.<br />Your next target is to reach 600 upvotes. <p dir="auto"><sub><em>You can view your badges on <a href="https://hivebuzz.me/@catleen" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">your board and compare yourself to others in the <a href="https://hivebuzz.me/ranking" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Ranking<br /> <sub><em>If you no longer want to receive notifications, reply to this comment with the word <code>STOP <p dir="auto"><strong><span>Check out the last post from <a href="/@hivebuzz">@hivebuzz: <table><tr><td><a href="/hivebuzz/@hivebuzz/cbrs-infographic"><img src="https://images.hive.blog/64x128/https://i.imgur.com/JDca2Q7.png" /><td><a href="/hivebuzz/@hivebuzz/cbrs-infographic">CBRS Hive Infographic Contest - Get your badge and win 1000 HIVE<tr><td><a href="/hive-122221/@hivebuzz/pum-202210-delegations"><img src="https://images.hive.blog/64x128/https://i.imgur.com/fg8QnBc.png" /><td><a href="/hive-122221/@hivebuzz/pum-202210-delegations">Our Hive Power Delegations to the October PUM Winners <h6>Support the HiveBuzz project. <a href="https://hivesigner.com/sign/update_proposal_votes?proposal_ids=%5B%22199%22%5D&approve=true" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Vote for <a href="https://peakd.com/me/proposals/199" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">our proposal!

Thank you hive fam

Medyo nakaka lito sis @catleen pero Im a student of AMA computer learning center before sis meron kmi nagpagaralan na Ganyan pero dko na ganu matandaan Yung iba