Hi, I am currently making an assigment for JAVA but I am stuck. I have to make a birthdate from the three parameters: day, month and year, which are numbers = int. With this I have to put in some checks for valid dates. That part I think is done, but I get stuck at the following:
I want let an if statement check the day, if the day is correct, this block of code should be run trough

 if (dag >=1 && dag <=31) 
            {
               datum = dag; 
            }

"datum" Is a String, because I want to get the date like this: DD-MM-YYY
And "dag" is an Int. So whenever I try to compile this, bluej gives an error at this part saying "incompatible types". I assume this is because I try to place a Int in a String. Is this possible in any way, because I can't find out how.

One way to convert an integer to String is to use Integer.toString(A_NUMBER). The static method will return a string of the number. Please read more on Integer API.

commented: good suggestion +4
you can do that by creating a method that return string ...something like
public String toString(){
return String.format(arg)
}


let the arg represent the parameter you want to validate..I hope this would be of help

use the pre-built methods:

int a=5;
String b = Integer.toString(a);
//b="5"
String b=5;
int a=Integer.parseInt(b);
//a=5
commented: good example +4

After some fiddling with the code I finally found out how to do it. Thank you very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.