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.

4 Years
Discussion Span
Last Post by TheMrPatrick

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.

Votes + Comments
good suggestion
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);
String b=5;
int a=Integer.parseInt(b);

Edited by Lucaci Andrew

Votes + Comments
good example

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.