By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,397 Members | 2,515 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,397 IT Pros & Developers. It's quick & easy.

Illegal start of type

P: 1
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?

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. class ClockTalk {
  4.     public static void main(String[] arguments) {
  5.         //get current time and date
  6.         Calenda now = Calendar.getInstance();
  7.         int hour = now.get(Calendr.HOUR_OF_DAY);
  8.         int minute = now.get(Calendar.MINUTE);
  9.         int month = now.get(Calendar.MONTH) + 1;
  10.         int day = now.get(Calendar.DAY_OF_MONTH);
  11.         int year = now.get(Calendar.YEAR);
  12.  
  13.         //display greeting
  14.         if (hour < 12) {
  15.             System.out.println("Good morning.\n");
  16.         } else if (hour < 17) { 
  17.             System.out.println("Good afternoon.\n");
  18.         } else {
  19.             System.out.println("Good evening.\n");
  20.         }
  21.  
  22.         //begin time message by showing the minutes
  23.         System.our.print("It's ");
  24.         if (minute != 0)
  25.             System.out.print(" " + minute + " ");
  26.             System.out.print( (minute !=1) ? "minutes" :
  27.                 "minute");
  28.             System.out.print(" past");
  29.  
  30.  
  31.  
  32.     //Display the hour
  33.     System.out.print(" ");                              //illegal start of type
  34.     System.out.print( (hour > 12) ? (hour - 12) : hour);
  35.     System.out.print(" o'clock on ");
  36.     }
  37.  
  38.     //display the name of the month
  39.  
  40.     switch (month) {
  41.         case 1:
  42.             System.out.print("January");
  43.             break;
  44.         case 2:
  45.             System.out.print("Febuary");
  46.             break;
  47.         case 3:
  48.             System.out.print("March");
  49.             break;
  50.         case 4:
  51.             System.out.print("April");
  52.             break;
  53.         case 5:
  54.             System.out.print("May");
  55.             break;
  56.         case 6:
  57.             System.out.print("June");
  58.             break;
  59.         case 7:
  60.             System.out.print("July");
  61.             break;
  62.         case 8:
  63.             System.out.print("Augest");
  64.             break;
  65.         case 9:
  66.             System.out.print("September");
  67.             break;
  68.         case 10:
  69.             System.out.print("October");
  70.             break;
  71.         case 11:
  72.             System.out.print("November");
  73.             break;
  74.         case 12:
  75.             System.out.print("December");
  76.     }
  77.  
  78.     //Display the date and year
  79.     {
  80.         System.out.println(" " + day ", " + year + ".");
  81.  
  82. }
Feb 21 '08 #1
Share this Question
Share on Google+
2 Replies


BigDaddyLH
Expert 100+
P: 1,216
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
Feb 21 '08 #2

BigDaddyLH
Expert 100+
P: 1,216
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?

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. class ClockTalk {
  4.     public static void main(String[] arguments) {
  5.         ...
  6.     //Display the hour
  7.     System.out.print(" ");                              //illegal start of type
  8.     System.out.print( (hour > 12) ? (hour - 12) : hour);
  9.     System.out.print(" o'clock on ");
  10.     }
  11.  
  12.  
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.print(" o'clock on ");

Also note this common mistake:
Expand|Select|Wrap|Line Numbers
  1. if (minute != 0)
  2.     System.out.print(" " + minute + " ");
  3.     System.out.print( (minute !=1) ? "minutes" :"minute");
  4.     System.out.print(" past");
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..):
Expand|Select|Wrap|Line Numbers
  1. if (minute != 0) {
  2.     System.out.print(" " + minute + " ");
  3.     System.out.print( (minute !=1) ? "minutes" :"minute");
  4.     System.out.print(" past");
  5. }
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:
Expand|Select|Wrap|Line Numbers
  1. public class Example {
  2.  
  3. }
And then recompile after you add each statement. You code will never get as ragged as what you posted.
Feb 21 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.