Illegal start of type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mole40
    New Member
    • Feb 2008
    • 1

    Illegal start of type

    Hello! I'm very new to writing java. And I keep getting the "Illegal Start of Type" error. I've tried everything to fix it. can anyone help me?

    [CODE=Java]import java.util.*;

    class ClockTalk {
    public static void main(String[] arguments) {
    //get current time and date
    Calenda now = Calendar.getIns tance();
    int hour = now.get(Calendr .HOUR_OF_DAY);
    int minute = now.get(Calenda r.MINUTE);
    int month = now.get(Calenda r.MONTH) + 1;
    int day = now.get(Calenda r.DAY_OF_MONTH) ;
    int year = now.get(Calenda r.YEAR);

    //display greeting
    if (hour < 12) {
    System.out.prin tln("Good morning.\n");
    } else if (hour < 17) {
    System.out.prin tln("Good afternoon.\n");
    } else {
    System.out.prin tln("Good evening.\n");
    }

    //begin time message by showing the minutes
    System.our.prin t("It's ");
    if (minute != 0)
    System.out.prin t(" " + minute + " ");
    System.out.prin t( (minute !=1) ? "minutes" :
    "minute");
    System.out.prin t(" past");



    //Display the hour
    System.out.prin t(" "); //illegal start of type
    System.out.prin t( (hour > 12) ? (hour - 12) : hour);
    System.out.prin t(" o'clock on ");
    }

    //display the name of the month

    switch (month) {
    case 1:
    System.out.prin t("January");
    break;
    case 2:
    System.out.prin t("Febuary");
    break;
    case 3:
    System.out.prin t("March");
    break;
    case 4:
    System.out.prin t("April");
    break;
    case 5:
    System.out.prin t("May");
    break;
    case 6:
    System.out.prin t("June");
    break;
    case 7:
    System.out.prin t("July");
    break;
    case 8:
    System.out.prin t("Augest");
    break;
    case 9:
    System.out.prin t("September" );
    break;
    case 10:
    System.out.prin t("October");
    break;
    case 11:
    System.out.prin t("November") ;
    break;
    case 12:
    System.out.prin t("December") ;
    }

    //Display the date and year
    {
    System.out.prin tln(" " + day ", " + year + ".");

    }[/CODE]
    Last edited by BigDaddyLH; Feb 21 '08, 03:42 AM. Reason: added code tags
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Originally posted by mole40
      Hello! I'm very new to writing java. And I keep getting the "Illegal Start of Type" error. I've tried everything to fix it. can anyone help me?

      [CODE=Java]import java.util.*;

      class ClockTalk {
      public static void main(String[] arguments) {
      ...
      //Display the hour
      System.out.prin t(" "); //illegal start of type
      System.out.prin t( (hour > 12) ? (hour - 12) : hour);
      System.out.prin t(" o'clock on ");
      }

      [/CODE]
      The error is because your braces don't match. The brace that opens the main nethod is closed by that orphan brace after System.out.prin t(" o'clock on ");

      Also note this common mistake:
      [CODE=Java]if (minute != 0)
      System.out.prin t(" " + minute + " ");
      System.out.prin t( (minute !=1) ? "minutes" :"minute");
      System.out.prin t(" past");[/CODE]
      The first output line will print iff minute != 0, but the second and third line will always print. Why? They are not part of the if statement, but are after it! Solution: always put braces around the "then" part (and the else, and all loop bodies, etc..):
      [CODE=Java]if (minute != 0) {
      System.out.prin t(" " + minute + " ");
      System.out.prin t( (minute !=1) ? "minutes" :"minute");
      System.out.prin t(" past");
      }[/CODE]
      There are also several typos and misspellings.

      One more piece of advice: this is too much code to compile all at once for a beginner. Compile when you enter almost nothing:
      [CODE=Java]public class Example {

      }[/CODE]
      And then recompile after you add each statement. You code will never get as ragged as what you posted.

      Comment

      Working...