Click here to Skip to main content
14,695,503 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've been working on this for days.. I cant figure out what I'm doing wrong and why it wont run. It's supposed to prompt the user to enter a month and year then it should tell the number of days in that month..

package JavaProgram2;

public class java {

	public static void main(String[] args) {



  int month;
  int year;
  bool leapYear = false;
  //Where user enters a month
  cout << "Enter a month" << endl; 
  cin >> month;
  //Where user enters year
  cout <<"Enter a year" << endl; 
  cin >> year;
  if (month == 1){ 
    cout << "January " << year << " has 31 days " << endl; 
  else if (month == 2 && leapYear == true){
    cout << "February " << year << " has 29 days " << endl;
  else if (month == 2 && leapYear == false){
    cout << "Febuary " << year << "has 28 days " << endl;
  else if (month == 3){
    cout << "March " << year << "has 31 days " << endl;
  else if (month == 4){
    cout << "April " << " has 30 days " << endl;
  else if (month == 5){
    cout << "May " << year << "has 31 days " << endl;
  else if (month == 6){
    cout << "June " << year << " has 30 days " << endl;
  else if (month == 7){
    cout << "July " << year << "has 30 days " << endl;
  else if (month == 8){
    cout << "August " << year << "has 31 days " << endl;
  else if (month == 9){
    cout << "September " << year << " has 30 days " << endl;
  else if (month == 10){
    cout << "October " << year << "has 31 days" << endl;
  else if (month == 11){
    cout << "November " << year << "has 30 days" << endl;
  else if (month == 12){
    cout << "December " << year << "has 31 days" << endl;
    cout << "Invalid Month" << endl;
  return 0;

What I have tried:

Everything I know to try..............................
Updated 12-Jan-18 11:00am
[no name] 18-Nov-17 18:03pm
What is the Problem?
What Input does not deliver the expected Output? Present an example...
Do you realize that you don't set leapYear based on the user Input?
Richard MacCutchan 19-Nov-17 3:07am
Surely even as a newbie, you can see that your main method contains no code.
Member 13525421 19-Nov-17 11:40am
I know the main method is wrong because it keeps saying "cant load main method".. but as a newbie no, I don't know what to do.
Richard MacCutchan 19-Nov-17 11:47am
Go to The Java™ Tutorials[^] and spend some useful time learning how to create Java programs.
Member 13525421 19-Nov-17 11:41am
Do you mind to tell me what I should put for leap year?
Richard MacCutchan 19-Nov-17 11:48am
Nothing, since that is C++ code, not Java.
ThilinaMD 13-Jan-18 2:03am
java does not support cout it ti C++

I see some issues in your code, such as the lack of proper formatting and the use of functions not available in Java.

In Java, bool is the the proper keyword for a boolean, however in C++ that is correct. The proper keyword to initialize a boolean in Java happens to be boolean

Cout is not a Java function, it happens to be a C++ command utilized to output to console.
Java uses the System.out library to output(hence the "out").

Cin follows the previous issue of being a C++ function; Java utilizes the java.util.Scanner library for console input.

There also exists an issue where your main method
public static void main(String[] args)
should encapsulate the code you have written out, rather than go below the main method AND the class declaration.
Do not Repost same question or almost.
"Error: could not find or load main class iostream" please help![^]
I cant figure out what I'm doing wrong and why it wont run.

The same cause lead to same result.
As you already have been told in previous question, you are happily mixing Java code with C++ code, and you wonder why it don't work.
Even if they remotely look alike you can't mix Java and C++ pieces of code.

Advice: learn Java properly with a tutorial, then come back to this problem.
This isn't even all Java code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900