Table of Contents
In this tutorial, we will discuss the concept of the Switch case statement in Java language
In this post, we will learn how to use the switch case statement in java language
Syntax
How to work switch statements
Example 2
public class switchnotd{ // start of class
public static void main(String args[]){// start of main method
int age=10; //variable Assignment
switch(age){ //swich expression
case 10: //if statement is true this case executed
System.out.println(“10”); //if false go to next case
case 20: //if statement is true this case executed
System.out.println(“20”);//if false go to next case
case 30: //if statement is true this case executed
System.out.println(“30”);//if false go to next case
default:System.out.println(“age not match”);
// all case are false this statement executed
}
} / end of main method
Example 3
class age{
public static void main (String args[]){
int age=20;
switch(age){
case 10:
System.out.println(“you age is ten”);
break;
case 20:
System.out.println(“you age is twenty”);
break;
case 30:
System.out.println(“you age is thirty”);
break;
case 40:
System.out.println(“you age is forty”);
break;
default:
System.out.println(“i don’t no age”);
break;
}
}
}
Similar post
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.