Write a program that demonstrate if-else statement

Category : Java | Sub Category : Control Statement | By Prasad Bonam Last updated: 2020-09-28 13:43:33 Viewed : 560


(Control Statement)

Write a program that demonstrate if-else statement

Source Code: IfElse.java

/**

 * Write a programme that demonstrate if-else statement

 */

public class IfElse { // This line daclare a new class & the class defination is start.

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

           int month = 4; // April

           String season; // daclare a string name season.

           if (month == 12 || month == 1 || month == 2)

                season = "winter"; // if above condition is true than print winter.

           else if (month == 3 || month == 4 || month == 5)

                season = "Spring"; // if above condition is true than print Spring.

           else if (month == 6 || month == 7 || month == 8)

                season = "Summer"; // if above condition is true than print Summer.

           else if (month == 9 || month == 10 || month == 11)

                season = "Auntumn"; // if above condition is true than print Auntumn.

           else

                season = "Bogus Month"; //

           System.out.println("April is in the " + season + ".");

// this print the season of month.

     } // end of main programme

}

Output: April is in the Spring.




Search
Related Articles

Leave a Comment: