How to declare a method with 2 parameters of different types in the main method in java?
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 == tru开发者_运维知识库e)
{
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 ");
}
}
}
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.
The correct way to do what you've asked is to change System.out.println(numberMonth)
to the following:
System.out.println(numberMonth(anInt, aString));
Where anInt
is an int
and aString
is a string. You could also do this with specific values, like so:
System.out.println(numberMonth(5, "leap"));
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 a String
for your leapYear
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
or false
. So, rather than storing a string with the values "leap"
or "no leap"
, you could declare a boolean variable. Here's a brief example:
public static int numberMonth(int parseMonth, boolean leapYear)
{
if(leapYear)
{
//if leapYear is true, this code will be executed
}
else
{
//if leapYear is false, this block will be executed
}
}
Take the time now to learn these basic, fundamental techniques. It will save you a mountain of frustration and wasted time in the future.
精彩评论