Re: PRINTING DIAMOND SHAPE WITH LOOPS!
From: Paul Lutus (nospam_at_nosite.zzz)
Date: 08/27/04
- Next message: Oscar kind: "Re: HttpSession getID method not returning unique ID"
- Previous message: Liz: "Re: Java Delegates, Inner Classes & final"
- In reply to: Jay Dean: "Re: PRINTING DIAMOND SHAPE WITH LOOPS!"
- Next in thread: Gordon Beaton: "Re: PRINTING DIAMOND SHAPE WITH LOOPS!"
- Reply: Gordon Beaton: "Re: PRINTING DIAMOND SHAPE WITH LOOPS!"
- Reply: Jay Dean: "Re: PRINTING DIAMOND SHAPE WITH LOOPS!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 26 Aug 2004 22:18:00 -0700
Jay Dean wrote:
> Paul,John,Adam,Liz, at al.,.
> Thank you all for your individual help and input into trying to
> helping me. Sorry, all I needed was one sentence:"Post your code that
> is not working". Instead, I was subjected to all sorts of unfair
> stereotypes.
Neither unfair nor a stereotype. Applying a sterotype would have required us
to use our misguided imaginations instead of the content of your posts.
There was no need for that. You asked a student question, then claimed
falsely not to be a student, while explaining what kind of student you are.
No imagination required.
But we can move past that, yes?
> Anyway, I tested John and Paul's codes in a main method and
> they worked perfectly,even thogh Paul intentionally meant to confuse
> me.
No, not at all. I meant to write a concise, efficient embodiment of the
algorithm. Its complexity to a student was a coincidental side effect.
Experienced programmers can see how it works at a glance. This makes it
space-efficient without sacrificing comprehensibility and maintainability.
> However, I have two main issues...
> (1)I STILL want HELP to implement the method with one of my OWN
> UNFINISHED codes below
That's more like it. We are much happier helping you with your own code. You
have no idea how much more acceptable this is.
> and
> (2) I would like you to help me understand your code with clear
> commenting if possible..., especially, does a "-" sign in front of an
> int variable imply ("opposite direction")?
No, it is called a unary operator: -1 means "minus one". In the same way, -x
means "minus x".
> Also, what do the symbols
> ?,:,etc mean in Java?
In this specific example it means:
(logical true-false test)?(do this if true):(do this if false);
Like this (not compiled or tested):
int x = -1;
System.out.println((x < 0)?"X is less than zero":"X is equal to or greater
than zero");
> (1). Here's one of my many attempts that I have struggled with for
> days:
Okay, with all respect I ask that you abandon this code entirely and start
with something simpler.
> if(i=((n+1)/2)+1) break;
And please do not use "break" in a program of this kind! This is very bad
practice. Constructs like "break" have a place, but they are very much out
of place in a simple, deterministic algorithm like this.
1. "Divide and conquer." Start with something simple, make it work, be sure
you understand it, and move on. Do not try to solve the entire problem in
one go.
2. Experiment with loops that create a row of spaces or a row of asterisks.
Think about how they work. Do not get bogged down with ambitious blocks of
code meant to solve the main problem, but that end up not doing what you
want and that you are unwilling to abandon.
3. Think about the logical flow of the program, and how to derive all the
required values from a few variables and control structures. Build
something easy first, before moving on to the main task.
4. Avoid "break." Breaks are innately confusing and to be avoided. Including
a break in a program is in most cases an admission of defeat in sorting out
a logical control flow for the algorithm.
With all respect, fixing the code you posted would not be particularly
productive, although I want to say it sends a very positive signal of your
seriousness, and you are to be commended for doing it.
-- Paul Lutus http://www.arachnoid.com
- Next message: Oscar kind: "Re: HttpSession getID method not returning unique ID"
- Previous message: Liz: "Re: Java Delegates, Inner Classes & final"
- In reply to: Jay Dean: "Re: PRINTING DIAMOND SHAPE WITH LOOPS!"
- Next in thread: Gordon Beaton: "Re: PRINTING DIAMOND SHAPE WITH LOOPS!"
- Reply: Gordon Beaton: "Re: PRINTING DIAMOND SHAPE WITH LOOPS!"
- Reply: Jay Dean: "Re: PRINTING DIAMOND SHAPE WITH LOOPS!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|