Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #37053

Re: A small challenge at beginner's level

From Andreas Leitgeb <avl@logic.at>
Newsgroups comp.lang.java.programmer
Subject Re: A small challenge at beginner's level
Date 2017-08-03 14:02 +0000
Organization A noiseless patient Spider
Message-ID <slrnoo6bf2.o2q.avl@logic.at> (permalink)
References <exercise-20170803112636@ram.dialup.fu-berlin.de> <slrnoo6aad.o2q.avl@logic.at>

Show all headers | 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


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