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


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

Re: A small challenge at beginner's level

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: A small challenge at beginner's level
Date Thu, 3 Aug 2017 22:47:33 -0000 (UTC)
Organization A noiseless patient Spider
Lines 65
Message-ID <om0965$6tt$1@dont-email.me> (permalink)
References <exercise-20170803112636@ram.dialup.fu-berlin.de> <slrnoo6aad.o2q.avl@logic.at>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Thu, 3 Aug 2017 22:47:33 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="c814652e0e2530604af510c44ffd91c9"; logging-data="7101"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EfsqSzvGbLfid47q3qcFsBTk3kYaDQK0="
User-Agent Pan/0.141 (Tarzan's Death; 168b179 git.gnome.org/pan2)
Cancel-Lock sha1:JP6wLEOPiczqnvJJ2sGFEfX+N8M=
Xref csiph.com comp.lang.java.programmer:37062

Show key headers only | View raw


On Thu, 03 Aug 2017 13:42:46 +0000, Andreas Leitgeb 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 int 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 ;-)

At the bare minimum you should be teaching:

- proper use of insertion symbols in format strings - even showing them
  "%5.5s" as a bad example is abominable

- at least one conditional form: 
  either 
     if (condition) ... else ....;
  or 
     ( condition ? trueval: falseval )

- assignments

If only because showing them both condition forms and assignments would
let them write:

  double selector = Math.round(Math.random());
  System.out.println("You have " + (selector > 0.5 ? "won" : "lost"));

or

  double selector = Math.round(Math.random());
  String result = "lost";
  if (selector > 0.5) 
     result = "won";

  System.out.println("You have " + result);

Both of which are, in my opinion anyway, both simple to write and simple 
to understand.

If you're not going to teach them anything about conditionals at the point
where you give them the exercise, then don't set them problems that are 
expected to produce conditional results: just stick to calculations, 
e.g. ask them to calculate the difference Math.PI and 22 divided by 7:

double diff = Math.abs(Math.PI - (22.0/7.0));
System.out.println("22/7 differs from Pi by " + diff);


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

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