1

I wrote this piece of code but when I try to compile it says:

 error: class, interface, or enum expected
 }
 ^
1 error

How can I fix that? I don't understand. Is something wrong with the parentheses? What does enum mean? I have checked the parenthesis and everything seems in order.

import java.util.Scanner;

public class Horoscope {
  public static void main(String[] args) {

    System.out.println("Please enter month of Birth: ");
    Scanner month = new Scanner(System.in);
    System.out.println("Please enter day of Birth: ");
    Scanner day = new Scanner(System.in);
    System.out.println("Your horoscope is ");

    if ((month == 3 && day >= 21 && day <= 31) || (month == 4 && day >= 1 && day <= 19)) {
        System.out.print("Aries");
     }
   if ((month == 4 && day >= 20 && day <= 30) || (month == 5 && day >= 1 && day <= 20)) {
        System.out.print("Taurus");
     }
   if ((month == 5 && day >= 21 && day <= 31) || (month == 6 && day >= 1 && day <= 20)) {
        System.out.print("Gemini");
     }
   if ((month == 6 && day >= 21 && day <= 30) || (month == 7 && day >= 1 && day <= 22)) {
       System.out.print("Cancer");
     }
  if ((month == 7 && day >= 23 && day <= 31) || (month == 8 && day >= 1 && day <= 22)) {
        System.out.print("Leo");
     }
  if ((month == 8 && day >= 23 && day <= 31) || (month == 9 && day >= 1 && day <= 22)) {
        System.out.print("Virgo");
     }
  if ((month == 9 && day >= 23 && day <= 30) || (month == 10 && day >= 1 && day <= 22)) {
        System.out.print("Libra");
     }
  if ((month == 10 && day >= 23 && day <= 31) || (month == 11 && day >= 1 && day <= 21)) {
        System.out.print("Scorpio");
     }
  if ((month == 11 && day >= 22 && day <= 30) || (month == 12 && day >= 1 && day <= 21)) {
        System.out.print("Sagittarius");
     }
  if ((month == 12 && day >= 22 && day <= 31) || (month == 1 && day >= 1 && day <= 19)) {
        System.out.print("Capricorn");
     }
  if ((month == 1 && day >= 20 && day <= 31) || (month == 2 && day >= 1 && day <= 18)) {
        System.out.print("Aquarius");
     }
  if ((month == 2 && day >= 19 && day <= 29) || (month == 3 && day >= 1 && day <= 20)) {
        System.out.print("Pisces");
    }
}
}
}
}

Thanks

11
  • What do you mean "You checked"? There are clearly superfluous braces there. Commented Jul 12, 2015 at 13:14
  • @RealSkeptic What do you mean by braces? { or ( ? Can you please help? I am really new to this :) Commented Jul 12, 2015 at 13:15
  • 1
    remove two } from last part of the code, and i believe you need to read from the user the month and the day, by using Scanner month = new Scanner(System.in) you are just tell the compiler to use the in stream only . you have to say int mnth = month.nextInt() Commented Jul 12, 2015 at 13:16
  • 1
    "Braces" in English mean {} (full name: "curly braces"). Brackets mean [] (full name: square brackets). And parentheses mean (). Commented Jul 12, 2015 at 13:16
  • 1
    Welcome bro :) , please accept an answer to close the question . Commented Jul 12, 2015 at 13:27

2 Answers 2

1

By using Scanner month = new Scanner(System.in) you are just tell the compiler to use the in stream only . you have to say int mnth = month.nextInt() Change this part

System.out.println("Please enter month of Birth: ");
Scanner month = new Scanner(System.in);
System.out.println("Please enter day of Birth: ");
Scanner day = new Scanner(System.in);
System.out.println("Your horoscope is ");

with

int month=0 , day=0;
Scanner scanner= new Scanner(System.in);
System.out.println("Please enter month of Birth: ");
month = scanner.nextInt();
System.out.println("Please enter day of Birth: ");
day = scanner.nextInt();
System.out.println("Your horoscope is ");
Sign up to request clarification or add additional context in comments.

Comments

1

Few things you should study before you start to write the code.

This is your correct code.

import java.util.Scanner;

public class Horoscope {

    public static void main(String[] args) {

        System.out.println("Please enter month of Birth: ");
        Scanner sc = new Scanner(System.in);
        int month = sc.nextInt();
        System.out.println("Please enter day of Birth: ");
        int day = sc.nextInt();
        System.out.println("Your horoscope is ");

        if ((month == 3 && day >= 21 && day <= 31) || (month == 4 && day >= 1 && day <= 19)) {
            System.out.print("Aries");
        }
        if ((month == 4 && day >= 20 && day <= 30) || (month == 5 && day >= 1 && day <= 20)) {
            System.out.print("Taurus");
        }
        if ((month == 5 && day >= 21 && day <= 31) || (month == 6 && day >= 1 && day <= 20)) {
            System.out.print("Gemini");
        }
        if ((month == 6 && day >= 21 && day <= 30) || (month == 7 && day >= 1 && day <= 22)) {
            System.out.print("Cancer");
        }
        if ((month == 7 && day >= 23 && day <= 31) || (month == 8 && day >= 1 && day <= 22)) {
            System.out.print("Leo");
        }
        if ((month == 8 && day >= 23 && day <= 31) || (month == 9 && day >= 1 && day <= 22)) {
            System.out.print("Virgo");
        }
        if ((month == 9 && day >= 23 && day <= 30) || (month == 10 && day >= 1 && day <= 22)) {
            System.out.print("Libra");
        }
        if ((month == 10 && day >= 23 && day <= 31) || (month == 11 && day >= 1 && day <= 21)) {
            System.out.print("Scorpio");
        }
        if ((month == 11 && day >= 22 && day <= 30) || (month == 12 && day >= 1 && day <= 21)) {
            System.out.print("Sagittarius");
        }
        if ((month == 12 && day >= 22 && day <= 31) || (month == 1 && day >= 1 && day <= 19)) {
            System.out.print("Capricorn");
        }
        if ((month == 1 && day >= 20 && day <= 31) || (month == 2 && day >= 1 && day <= 18)) {
            System.out.print("Aquarius");
        }
        if ((month == 2 && day >= 19 && day <= 29) || (month == 3 && day >= 1 && day <= 20)) {
            System.out.print("Pisces");
        }
    }
}

2 Comments

but you only put one scanner?
One Scanner is enough for the entire program. Scanner defines the input stream. And with .nextInt(), you take the next integer input. You can take any number of inputs using a single Scanner. Refer the links in the answer. That will help you understand better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.