You are here: Home / Topics / Find Odd Even using Switch statement in Java

Find Odd Even using Switch statement in Java

Filed under: Java on 2023-08-12 20:52:05

// Even odd using switch case

class  EvenOdd
{
public static void main(String args[ ])
{
 for( int i=1 ; i<=10 ; i++ )
 {
  switch( i )
  {
   case 1:
   case 3:
   case 5:
   case 7:
   case 9:
    System.out.println( i + " - Odd Number." );
    break;
   case 2:
   case 4:
   case 6:
   case 8:
   case 10:
    System.out.println( i + " - Even Number." );
    break;
  }
 }
 System.out.println( " The End. " );
}
}

 

Output:

1 - Odd Number.
2 - Even Number.
3 - Odd Number.
4 - Even Number.
5 - Odd Number.
6 - Even Number.
7 - Odd Number.
8 - Even Number.
9 - Odd Number.
10 - Even Number.
 The End

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.