Java program to display Astrological sign or Zodiac sign for given date of birth

Java 8Object Oriented ProgrammingProgramming

Each date of birth corresponds to a given Zodiac sign. A table that demonstrates these signs and their corresponding dates is given below −

Zodiac SignDate
AriesMarch 21 - April 19
TaurusApril 20 - May 20
GeminiMay 21 - June 20
CancerJune 21 - July 22
LeoJuly 23 - August 22
VirgoAugust 23 - September 22
LibraSeptember 23 - October 22
ScorpioOctober 23 - November 21
SagittariusNovember 22 - December 21
CapricornDecember 22 - January 19
AquariusJanuary 20 - February 18
PiscesFebruary 19 - March 20

A program that displays the Astrological sign or Zodiac sign for a given date of birth is given as follows.

Example

 Live Demo

public class Example {
   public static void main (String[] args) {
      int day = 7;
      String month = "August";
      String sign="";
      if (month == "January") {
         if (day < 20)
            sign = "Capricorn";
         else
            sign = "Aquarius";
      }
      else if (month == "February") {
         if (day < 19)
            sign = "Aquarius";
         else
            sign = "Pisces";
      }
      else if(month == "March") {
         if (day < 21)
            sign = "Pisces";
         else
            sign = "Aries";
      }
      else if (month == "April") {
         if (day < 20)
            sign = "Aries";
         else
            sign = "Taurus";
      }
      else if (month == "May") {
         if (day < 21)
            sign = "Taurus";
         else
            sign = "Gemini";
      }
      else if( month == "June") {
         if (day < 21)
            sign = "Gemini";
         else
            sign = "Cancer";
      }
      else if (month == "July") {
         if (day < 23)
            sign = "Cancer";
         else
            sign = "Leo";
      }
      else if( month == "August") {
         if (day < 23)
            sign = "Leo";
         else
            sign = "Virgo";
      }
      else if (month == "September") {
         if (day < 23)
            sign = "Virgo";
         else
            sign = "Libra";
      }
      else if (month == "October") {
         if (day < 23)
            sign = "Libra";
         else
            sign = "Scorpio";
      }
      else if (month == "November") {
         if (day < 22)
            sign = "scorpio";
         else
            sign = "Sagittarius";
      }
      else if (month == "December") {
         if (day < 22)
            sign = "Sagittarius";
         else
            sign ="Capricorn";
      }
      System.out.println("The astrological sign for " + day + " " + month + " is " + sign );
   }
}

Output

The astrological sign for 7 August is Leo
raja
Published on 05-Dec-2018 16:18:01
Advertisements