Simple Java Program Demonstrating The Switch-Case Statements
The code is shared by Krishna Upadhyay(X)-Vissanji Academy
Code:
The code is shared by Krishna Upadhyay(X)-Vissanji Academy
Code:
/**
* Simple Java Program Demonstrating The Switch-Case Statements
*/
public class SwitchCaseDemo
{
public static void main(int i,char ch)//Taking input From BlueJ Interface
{
SwitchCaseDemo obj=new SwitchCaseDemo();
obj.display(i,ch);//Call By Value
}
public void display(int i,char ch)
{
switch(i)//Start Of Switch-Case Statemants For Integer i
{
case 1:
{
System.out.println("This Is Case 1");
break;
}
case 2:
{
System.out.println("This Is Case 2");
break;
}
case 3:
{
System.out.println("This Is Case 3");
break;
}
default:
{
System.out.println("Integer Value Is Incorrect");
break;
}
}
switch(ch)//Starting Of Switch-Case Statements For Character ch
{
case 'a':
{
System.out.println("This Is Case 'a'");
break;
}
case 'b':
{
System.out.println("This Is Case 'b'");
break;
}
case 'c':
{
System.out.println("This Is Case 'c'");
break;
}
default:
{
System.out.println("Character Value Is Incorrect");
}
}
}
}//End Of Class
Comment bellow for your query and feedback... :)* Simple Java Program Demonstrating The Switch-Case Statements
*/
public class SwitchCaseDemo
{
public static void main(int i,char ch)//Taking input From BlueJ Interface
{
SwitchCaseDemo obj=new SwitchCaseDemo();
obj.display(i,ch);//Call By Value
}
public void display(int i,char ch)
{
switch(i)//Start Of Switch-Case Statemants For Integer i
{
case 1:
{
System.out.println("This Is Case 1");
break;
}
case 2:
{
System.out.println("This Is Case 2");
break;
}
case 3:
{
System.out.println("This Is Case 3");
break;
}
default:
{
System.out.println("Integer Value Is Incorrect");
break;
}
}
switch(ch)//Starting Of Switch-Case Statements For Character ch
{
case 'a':
{
System.out.println("This Is Case 'a'");
break;
}
case 'b':
{
System.out.println("This Is Case 'b'");
break;
}
case 'c':
{
System.out.println("This Is Case 'c'");
break;
}
default:
{
System.out.println("Character Value Is Incorrect");
}
}
}
}//End Of Class
0 comments:
Confused? Feel free to ask
Post a Comment