Categories: Keyword in Java

The case keyword in Java programming language

The case keyword in Java programming language

In this tutorial, we will learn about the case keyword in java programming language

The case is used to label each branch in a switch statement, to execute a block of code in the case statement, which needs to an argument passed in switch statements.

A case block does not have an internal ending point. A break statement is typically used at the end of each case block. This helps to exit the switch statement.

Declaration

Syntax

The syntax of the case within the switch

int age=value;
switch(arg)
{
case 1: //case statement using case keyword
<statements>
break;
case 2:
<statements>
break;
default:
<statements>
}

Example

Program

public class switch_keyword{
public static void main (String args[]){

String Days="Sunday";
switch(Days){
case "Sunday": //case statement using case keyword
System.out.println("Today Sunday");
break;

case "Monday":
System.out.println("Today Monday");
break;

case "Tuesday":
System.out.println("Today Tuesday");
break;

case "Wednesday":
System.out.println("Today Tuesday");
break;

case "Thursday":
System.out.println("Today Thursday");
break;

case "Friday":
System.out.println("Today Friday");
break;

case "Saturday":
System.out.println("Today Saturday");
break;

default :
System.out.println("This is not a day");

}
}
}

In the above program, the value passed in switch statements, that is compared with every case statements sequence running from initial statements to end statements. Once case statements matched with a switch value the value of branch statement executed.

When the above code is compiled and executed, it will produce the following results

Today is Friday

 

 

There are other Java language keywords that are similar to this keyword

try keyword in Java

Catch keyword in Java

implements keyword in java

public Key words in Java

static in Java language

Volatile  in Java

Transient  in Java

Package  in Java

class  in Java

boolean  in Java

break  in Java

do  in Java

double  in Java

This  in Java

final  in Java

switch  in Java

interface  in java

extends  in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Usage of final  in Java

Usage of this  in Java

Finally  in Java language

 

 

The switch keyword in Java programming language
The continue keyword in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago