473,385 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Illegal start of type

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
2 4606
BigDaddyLH
1,216 Expert 1GB
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
1,216 Expert 1GB
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

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

Similar topics

3
by: Juhan | last post by:
Hi! I have a strange error in a console application that is hosted by IIS 5.0 and invokes a web service hosted on the same machine. A request form the web comes in and it is dispatched to a...
12
by: chump1708 | last post by:
main(int argc, char *argv) { (main && argc) ? main(argc-1, NULL) : return 0; //line 1 } 1. Can I know why using return causes an illegal syntax...I guess it has something to do with command...
6
by: BlueTrin | last post by:
Hello I was adapting a C version of SolvOpt in C++ to use it within a virtual class. However I am stuck with the overriding of evaluation and gradiant functions. cStepCurveEvaluator.cpp...
8
by: LuB | last post by:
Is this somehow illegal? template<typename T> class A { public: private:
1
by: Manish | last post by:
The code is as ... $folderlistfile = $path."xmlfile.xml"; /* <list> <details id="2"> <name>Books</name>
16
by: DBC User | last post by:
Hi, I have a small XML file, I uploaded to a web page. I have the following code to convert the content I downloaded from web to xml and is giving "Illegal characters in path", but when I try to...
2
by: dobbouk | last post by:
I'm getting these 2 errors and haven't got a clue whats causing them please java 43: illegal start of type for (i=0;i< Number_of_squares; i++) java 215 identifier expected } ...
2
by: Lambda | last post by:
The code is simple: // Token.h #ifndef TOKEN_H #define TOKEN_H #include <vector> #include <string> class Token
3
by: MrHenry007 | last post by:
Hello! I'm fairly new to c++ but I have been following tutorials and have created functions before, but not one using a string. I can't work out what the problem is here. The function is supposed...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.