Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37053
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Andreas Leitgeb <avl@logic.at> |
| 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 | <slrnoo6bf2.o2q.avl@logic.at> (permalink) |
| References | <exercise-20170803112636@ram.dialup.fu-berlin.de> <slrnoo6aad.o2q.avl@logic.at> |
| 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 |
Show key headers only | View raw
Andreas Leitgeb <avl@logic.at> wrote:
> Stefan Ram <ram@zedat.fu-berlin.de> 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"))
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: A small challenge at beginner's level Andreas Leitgeb <avl@logic.at> - 2017-08-03 13:42 +0000
Re: A small challenge at beginner's level Andreas Leitgeb <avl@logic.at> - 2017-08-03 14:02 +0000
Re: A small challenge at beginner's level Martin Gregorie <martin@address-in-sig.invalid> - 2017-08-03 22:47 +0000
Re: A small challenge at beginner's level Eric Douglas <e.d.programmer@gmail.com> - 2017-08-08 08:01 -0700
Re: A small challenge at beginner's level Sebastian <nowhere@nirvana.org> - 2017-08-08 22:59 +0200
Re: A small challenge at beginner's level Eric Douglas <e.d.programmer@gmail.com> - 2017-08-09 05:16 -0700
Re: A small challenge at beginner's level Arne Vajhøj <arne@vajhoej.dk> - 2017-08-08 21:00 -0400
csiph-web