-3

Im just started to learn Java and have a problem, hope you can help me.

import java.util.Date;
public class Main {

/**
* @param args the command line arguments
*/
public void main(String[] args) {
// TODO code application logic here

}
Date date = new Date();
long millis = date.getTime();
System.out.println(date);      <-- here i have a problem!
}

Print out dont working, i dont know why. Please help!

P.S. Sorry for my bad english.

Now i see, my fail. Thanks guiys!

Davy
  • 11
  • 3

2 Answers2

2

Put your code in main method or create a new method with all the statement that was want to execute:

public static void main(String args[]) {
   //date...
   //print
}

Or

private static void printDate() {
   //date stuff goes here.....
}

public static void main(String args[]) {
   printDate();
}

Main is the entry point from where the execution will begin. You would need to accumulate all the statements under a method or into main method to execute it.

SMA
  • 36,381
  • 8
  • 49
  • 73
1

You need to have System.out.println() within a method. Try entering it inside a method.