Understand Switch Case Statements in Java tutorial

Veröffentlicht am: 28 Juni 2024
auf dem Kanal: K. V. Siva Surya
37
2

Switch Case statements are similar to conditionals like the if statement. They basically check the equality of a value against other values. You can do the exact same thing using conditionals by just checking if(value==anotherValue) but it is more efficient and definitely structures your code better when you use switch Case Statements.

Switch Case statements involve two main keywords- switch, and case. The video isn't going to just explain what these keywords mean but it's going to help you get an intuitive understanding about them.

I hope the video was helpful. If it was, please don't forget to like, share, and subscribe. It's free and it helps me a lot

Program:

import java.util.*;
public class Switchcase {
public static void main(String[]args){

Scanner sa=new Scanner(System.in);
System.out.println("enter 1 for pizza");
System.out.println("Enter 2 for burger");
System.out.println("Enter 3 for biryani");
int value= sa.nextInt();

switch(value){
case 1: System.out.println("Pizza!");
break;
case 2: System.out.println("burger!");
break;
}

}


}

I hope this sample program helps out!


Auf dieser Seite können Sie das Online-Video Understand Switch Case Statements in Java tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer K. V. Siva Surya 28 Juni 2024 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 37 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!