如何在java的main方法中声明一个具有2个不同类型参数的方法?
如果我有这个方法: public static int numberMonth(int parseMonth, String LeapYear)
我将如何在此方法中打印出来:
public static void main(String[] args)
{
Boolean correctDate = false;
String date;
while (!correctDate)
{
// It is OK to embed the way you called the method checkInput(getInput())
// but for troubleshooting, it is easier for me to break into smaller steps.
// Request Date and get user response
date = getInput();
// Verfiy that the date entered contains a valid........
correctDate = checkInput(date);
// Display meesage to user
if (correctDate == true)
{
System.out.println("The date you entered is: " + date);
System.out.println(numberMonth);
System.out.println("The numerical date: " );
}
else
{
System.out.println("Please enter valid date ");
}
}
}
If i have this method: public static int numberMonth(int parseMonth, String leapYear)
how would i print it out in this method:
public static void main(String[] args)
{
Boolean correctDate = false;
String date;
while (!correctDate)
{
// It is OK to embed the way you called the method checkInput(getInput())
// but for troubleshooting, it is easier for me to break into smaller steps.
// Request Date and get user response
date = getInput();
// Verfiy that the date entered contains a valid........
correctDate = checkInput(date);
// Display meesage to user
if (correctDate == true)
{
System.out.println("The date you entered is: " + date);
System.out.println(numberMonth);
System.out.println("The numerical date: " );
}
else
{
System.out.println("Please enter valid date ");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看您之前的问题和代码片段,我认为您需要阅读类似 Oracle/Sun Java 教程的内容: http://download.oracle.com/javase/tutorial/java/index.html
其实一切都有答案。还有更多。
Looking on your previous questions and code snippets I think you need to read something like Oracle/Sun Java Tutorial: http://download.oracle.com/javase/tutorial/java/index.html
There are all answers in fact. And much more.
执行您所要求的操作的正确方法是将
System.out.println(numberMonth)
更改为以下内容:其中
anInt
是int
> 和aString
是一个字符串。您还可以使用特定值来执行此操作,如下所示:这里存在一个更大的问题,即您似乎缺乏 Java 语法最基本方面的基础。我强烈建议您参加课程、查看在线教程或购买一本书来学习计算机编程的基础知识,更具体地说是 Java 语言。
例如,在您的 相关问题,其中详细展示了
numberMonth
函数,虽然很多东西都很突出,但最引人注目的细节是使用String
为您的leapYear
值。当您处理真或假的信息时,您需要使用布尔数据类型。布尔变量只能包含两个值:true
或false
。因此,您可以声明一个布尔变量,而不是存储具有值"leap"
或"no Leap"
的字符串。这是一个简短的例子:现在花点时间学习这些基本的、基本的技术。这将为您节省未来大量的挫败感和浪费的时间。
The correct way to do what you've asked is to change
System.out.println(numberMonth)
to the following:Where
anInt
is anint
andaString
is a string. You could also do this with specific values, like so:There's a much larger issue at play here, being that it seems you lack a foundation in the most basic aspects of Java syntax. I would highly recommend taking a class, checking out an online tutorial, or getting a book to learn the basics of computer programming in general and the Java language more specifically.
For instance, in your related question where you show the
numberMonth
function in detail, while a lot of things stand out, the most striking detail is using aString
for yourleapYear
value. When you're dealing with information that is either true or false, you want to use the boolean data type. Boolean variables can only contain two values:true
orfalse
. So, rather than storing a string with the values"leap"
or"no leap"
, you could declare a boolean variable. Here's a brief example:Take the time now to learn these basic, fundamental techniques. It will save you a mountain of frustration and wasted time in the future.