Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Re: A small challenge at beginner's level Date: Thu, 3 Aug 2017 14:02:20 -0000 (UTC) Organization: A noiseless patient Spider Lines: 24 Message-ID: References: Reply-To: avl@logic.at Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 3 Aug 2017 14:02:20 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="3372b44961abf9e24369633da1e6adcb"; logging-data="9393"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19p5BvYOeLyELvJE0LR8/2n" User-Agent: slrn/1.0.2 (Linux) Cancel-Lock: sha1:ASWT+Wi6cQNSP6dvdLz9xXxIoxg= Xref: csiph.com comp.lang.java.programmer:37053 Andreas Leitgeb wrote: > Stefan Ram wrote: >> public final class Main >> { public static void main( final java.lang.String[] args ) >> { java.lang.System.out.println( ... ); }} >> >> where an expression can be inserted replacing >> the »...«. > Is it also allowed to fix the atrocious formatting? > >> and in between you may use literals of the types double, int >> and String, the operators »+«, »-«, »*« and »/« and >> parentheses »(...)« and method calls of static methods of >> the Java SE standard library. > String.format("you have%5.5s.",String.format("%"+(1+4*Math.round(Math.random()))+".1s"," lost")+"won") > certainly newbie level ;-) Apparently still too hard for me to get right at first... (Java doesn't use [precision] for 's', so it always printed same) alternative: (even shorter and simpler) String.format("you have %s.",String.format("%"+(1+Math.round(Math.random()))+"$s","won","lost"))