Hello fellow future programmers today I will share another program that you may know
This is the topic "Switch case "here you can choose any of the case that you input in your code .in the output .
Input import java.util.Scanner;
then Scanner day = new Scanner(System.in);
then System.out.println("Enter a day in a week);
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 .
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 .
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.
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.
Then don't forget too foot semicolon after the your System.out println.
Here is the source code!!
mport java.util.Scanner;
public class Main{
public static void main(String[]args) {
Scanner scanner= new Scanner(System.in);
System.out.print("Enter a day in a week:");
String day= scanner.nextLine();
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;
}
}
}
Here is the result 👇
Thank you for reading and I hope you learned something about my tutorial in java
you can use in laptop netbeans in mobile jvdroid compiler!😍
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
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
I gifted $PIZZA slices here:
@chichi18(2/5) 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):
Your next target is to reach 600 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out the last post from @hivebuzz:
Support the HiveBuzz project. Vote for 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