我究竟做错了什么? [英] What am I doing wrong?

查看:79
本文介绍了我究竟做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这方面工作了好几天..我无法弄清楚我做错了什么以及为什么它不会运行。它应该提示用户输入一个月和一年然后它应该告诉那个月的天数..



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) {
		

	}

}

   //Variables
 
  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;
  }
  else{
    cout << "Invalid Month" << endl;
  }
  return 0;
}





我的尝试:



我所知道的所有尝试..............................



What I have tried:

Everything I know to try..............................

推荐答案

我在你的代码中看到了一些问题,例如缺乏正确的格式以及使用Java中没有的函数。



In Java, bool 是布尔值的正确关键字,但在C ++中是正确的。在Java中初始化布尔值的正确关键字恰好是布尔



Cout 不是Java函数,它恰好是用于输出到控制台的C ++命令。

Java使用 System.out库输出(因此out)。



Cin 遵循上一期的C ++函数; Java利用 java.util.Scanner库进行控制台输入。



还有一个问题,你的主方法
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)

应该封装你写出来的代码,而不是在主要方法 AND 类声明之下。

should encapsulate the code you have written out, rather than go below the main method AND the class declaration.


不要重新发布相同或几乎相同的问题。

错误:无法找到或加载主类iostream请帮忙! [ ^ ]

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.



同样的导致相同的结果。

正如你在上一个问题中已经被告知的那样,你很高兴混合Java cod用C ++代码,你想知道为什么它不起作用。

即使它们看起来很相似,你也不能混合使用Java和C ++代码。

<建议:通过教程正确学习Java,然后回到这个问题。


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.


这甚至都不是所有的Java代码。
This isn't even all Java code.


这篇关于我究竟做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆