Write a program which demonstrate the if statement.

Category : Java | Sub Category : The Genesis of Java | By Runner Dev Last updated: 2020-09-27 13:01:52 Viewed : 195


Write a program which demonstrate the if statement.

Description: This java program in which we  make a class of name after making class we initialize x and y and give them value , then we give if condition in which we say if value of x is less than y than show ―x is less than y‖ , Now x multiply by 2 , Now we also give if condition x is equals to


/**

 *

 * Write a program which demonstrate the if statement

 *

 */

class IfSample { // This line daclare a class of name ifSample

     public static void main(String a[]) { // This line begins the main() method.

         int x, y; // this declares a variable

         x = 10; // this assign x the value 10.

         y = 20; // this assign y the value 20.

 

         if (x < y) // in this line we give if Statement that ifx is less than y than give

              System.out.println("x is less than y"); // This line outputs the string.

 

         x = x * 2; // multiply x by 2.

         if (x == y)

              System.out.println("now x is equal to y"); // this is a output line which show a string

 

         x = x * 2; // multiply again by 2

         if (x > y)

              System.out.println("now x is greater than y"); // this is a output line which show a string

     } // end of main program

} // end of a class

 OUTPUT:


Search
Related Articles

Leave a Comment: