Lession-4 if conditional statements, java, String compare

Lession--4  (Conditional statements)

There are two types of conditional statements in Java.
 if statements
 switch statements

Syntax :
     ///simple if condition, if condition true what to do
   if(condition)
   {

   }
   
    ///if else, if condition true and also false what to do
   if(condition)
   {


   }
   else
   {

   }

   ///if elseif statments multiple if
   if(condition)
   {

   }
   elseif(condition)
   {


   }
   elseif(condition)
   {

   }
   else
   {

   } 

ex 1: Script to display given number is even or odd

   class Evenodd
   {
     public static void main(String args[])
     {
       int x;
       x=5;
       if(x %2==0)
      {
        System.out.println("it is even number")
       }
      else
      {
        System.out.println("it is odd number")
      }
    }
  }

ex 2:script to compare 2 strings
   class compare
   {
    public static void main(String args[])
    {
     String s1,s2;
     s1="hello";
     s2="Hello";
     if(s1.matches(s2))
     {
      System.out.println("Both strings are same")
     }
     else
     {
      System.out.println("Both strings are not same")
     }
    }
   }

Comments