I've been working on writing and calling some methods, one that shows the current date and one that prints an asterisk pyramid. I've gotten to the point that the code will compile, but I've come across another problem. When I attempt to run in JGrasp, I get the error: The following file is missing class or inner class files: (file name). Proceeding before correcting this is not recommended.. Not finding anything about this on the internet, I tried again but in Eclipse. The error message I got this time is: Selection does not contain a main type.
I would really appreciate it if someone could overview my code and tell me if they see the problem. An explanation would also be awesome, as I'm trying to learn and better myself as a programmer. Thanks!!
import java.util.Calendar;
public class prcMeth {
public static void showCurrentDate() {
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DATE);
int year = cal.get(Calendar.YEAR);
System.out.println(year + "-" + month + "-" + day + " ");
}
public static boolean printPyramid(int n) {
int number = n;
if (number <= 0 || number > 10) {
System.out.println("Your parameter is invalid; you input n = " + n);
return false;
}
for (int row = 1; row <= number; row++) {
for (int space = number; space > row; space--) {
System.out.print(" ");
}
for (int star = 1; star <= row; star++) {
System.out.print("*");
System.out.println();
}
}
return true;
}
public static void main(String[] args) {
System.out.println("Hello, world!");
// Calling first function
showCurrentDate();
// Calling second function
System.out.println("n=0");
printPyramid(0);
System.out.println("n=1");
printPyramid(1);
System.out.println("n=5");
printPyramid(5);
System.out.println("n=10");
printPyramid(10);
System.out.println("n=11");
printPyramid(11);
}
}