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

Hi there ! Can anyone explain where what I’m doing wrong? After the input I want the program to print the astrological sign, but it doesn’t print anything…

Thank you in advance!

import java.io.*;
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);

System.out.println("Enter month and day:");

// String input
String month = myObj.nextLine();

// Numerical input
int day = myObj.nextInt();

}
}

class GFG {

static void zodiac_sign(int day, String month)
{
	String astro_sign="";
	
	// checks month and date within the
	// valid range of a specified zodiac
	if (month == "december"){
		
		if (day < 22)
		astro_sign = "Sagittarius";
		else
		astro_sign ="capricorn";
	}
		
	else if (month == "january"){
		if (day < 20)
		astro_sign = "Capricorn";
		else
		astro_sign = "aquarius";
	}
		
	else if (month == "february"){
		if (day < 19)
		astro_sign = "Aquarius";
		else
		astro_sign = "pisces";
	}
		
	else if(month == "march"){
		if (day < 21)
		astro_sign = "Pisces";
		else
		astro_sign = "aries";
	}
	else if (month == "april"){
		if (day < 20)
		astro_sign = "Aries";
		else
		astro_sign = "taurus";
	}
		
	else if (month == "may"){
		if (day < 21)
		astro_sign = "Taurus";
		else
		astro_sign = "gemini";
	}
		
	else if( month == "june"){
		if (day < 21)
		astro_sign = "Gemini";
		else
		astro_sign = "cancer";
	}
		
	else if (month == "july"){
		if (day < 23)
		astro_sign = "Cancer";
		else
		astro_sign = "leo";
	}
		
	else if( month == "august"){
		if (day < 23)
		astro_sign = "Leo";
		else
		astro_sign = "virgo";
	}
		
	else if (month == "september"){
		if (day < 23)
		astro_sign = "Virgo";
		else
		astro_sign = "libra";
	}
		
	else if (month == "october"){
		if (day < 23)
		astro_sign = "Libra";
		else
		astro_sign = "scorpio";
	}
		
	else if (month == "november"){
		if (day < 22)
		astro_sign = "scorpio";
		else
		astro_sign = "sagittarius";
	}
		
	System.out.println(astro_sign);
}
	
// Driver code
public static void main (String[] args)
{

	int day = 19;
	String month = "may";
	zodiac_sign(day, month);
		
}

}

REPLACE: if (month == “december”) {}
WITH: if (month.equalsIgnoreCase(“december”) {}
else if …
after your last else if YOU NEED an
else {System.out.println("Error on: " + day + “,” + month);}

1 Like

Thank you @JerryC !!!

I did that, but still it doesn’t show me the astrological sign , after I input the month and day

Your Main class never calls GFG.zodiac_sign. If you just run the GFG class’s main method, it should print out that specific info for May 19. Otherwise please post updated code so we can see what you are currently working with (in addition to any output you may be getting).