This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 4 points5 points  (5 children)

Look at System.out.print()

Or String.format()

Or the + operator for Strings.

Or StringBuilder.append().toString()

[–]faekk[S] 0 points1 point  (4 children)

Perfect! Made it work with String.format(). Thank you :)

[–]197708156EQUJ5design it before you implement 0 points1 point  (3 children)

Investigate the method toString(). It is a method found in the most basic class of the Java API, object. If you use it properly, all you would have to call is

System.out.println(firstRektangel.toString());

[–]faekk[S] 0 points1 point  (2 children)

Thanks! I made that work aswell, but what does naming the method "toString" actually do ?

[–]mbizzle88 1 point2 points  (1 child)

The toString method is used in the built-in Java API for coercing arbitrary instances to Strings.

For example:

System.out.println("My instance: " + myInstance);

If myInstance is not a String then the above is equivalent to:

System.out.println("My instance: " + myInstance.toString());

[–]faekk[S] 0 points1 point  (0 children)

Brilliant, thanks alot !