1

here is the program: (the file name is date.java)

class date {
    public static void main (String[] args) {
    int day, hour, minute;
    String firstline, half;

    firstline="the current imaginary time is:";
    day=24;
    hour=5;
    minute=36;

    String half;
    half="PM" ;


    System.out.println ("here is some program about the time kindof:");
    system.out.print (firstline) ;
    system.out.print (day) ;
    system.out.print (hour) ;
    system.out.print (":") ;
    system.out.print (minute) ;
    system.out.println (half) ;

    }
    }

here is what happens when i try to compile it in terminal:

david-allenders-macbook-pro:~ davidallender$ javac date.java
date.java:11: half is already defined in main(java.lang.String[])
    String half;
               ^
date.java:15: package system does not exist
    system.out.print (firstline) ;
              ^
date.java:16: package system does not exist
    system.out.print (day) ;
              ^
date.java:17: package system does not exist
    system.out.print (hour) ;
              ^
date.java:18: package system does not exist
    system.out.print (":") ;
              ^
date.java:19: package system does not exist
    system.out.print (minute) ;
              ^
date.java:20: package system does not exist
    system.out.println (half) ;
              ^
7 errors
david-allenders-macbook-pro:~ davidallender$ 

im learning from a book i found online. right now i'm in the chapter about variables. What did i do wrong?

1
  • 2
    When you dropped out of law school, perhaps?
    – T.E.D.
    Mar 2, 2010 at 23:53

4 Answers 4

6
String half;

you have already declared half earlier, remove this one

system.out.print (firstline) ;

Class names in java are case sensitive. system should be System

0
2

Remove the second 'String half;' in main. And system should be System.

1

Variables can be declared once in any scope and it is System not system.

1

You may want to try the Eclipse Java IDE (Integrated Development Environment) so that you can avoid these problems in the future. It will suggest fixes to these sort of simple errors.

http://www.eclipse.org/downloads/

Plus, it's free!

1
  • 1
    1) This should rather have been a comment. 2) Using an IDE before having a good grasp on Java would only make it more hard and opaque.
    – BalusC
    Mar 3, 2010 at 0:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.