Re: PRINTING DIAMOND SHAPE WITH LOOPS!

From: Jay Dean (fresh1700_at_yahoo.com)
Date: 08/28/04


Date: 27 Aug 2004 21:46:55 -0700

Okay, Paul, et al.,
   I tried the implementation of the shape again. This time I came soo
close. My main problem is where I have indicated with (---) in the
second else if condition. If you remove && j< (----) from it and test
it, you will see exactly what I am talking about. If I
replace(----)with m, where m is an int m=n; and then put m--; after
j++; at the end of the outer loop, it does not work. I would
appreciate your help with this.
   Also, I have a few questions below the code I need help with:
  
   int n=7,marker=(n/2)+1,i=1,j=1;
   
   while(i<=n)
   {
           while(j<=n)
           {
            if((i<marker)&&((marker-i)<j && j <(marker+i)))
              {System.out.print("*");}
              
            else if((i==marker))
              {System.out.print("*");}
              
            else if((i>marker)&&((i-marker)<j && j < (----)))
            {System.out.print("*");}
            
            else
              {System.out.print(" ");}
            j++;
           }
   System.out.println("");
   i++;
   j=1;
   }

 - In Java, if say I print out 7 rows of stars and at the end I want
to go back to the very beginning of the first line, or any other line
apart from the last one,how do I do that?

 - My guess is that (boolean)?(true):(false); is some sort of a
condensed if-else clause. If so, is there a limit on the lines of code
that one can put in place of the (true) and the (false)?

 - If say, 5 rows of dots are printed using System.out.print(ln), to
the screen, is it possible to create a second code that traverses the
dots and removes or erases some of them as I wish?

 - Does the Java API provide any info on ALL Java operators and
symbols?

I would appreciate your help.Thanks..

Jay Dean

        

Paul Lutus <nospam@nosite.zzz> wrote in message news:<10ith0bppb6b945@corp.supernews.com>...
> 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.



Relevant Pages

  • Re: Why NP Problem is Important and Practical Examples
    ... there is a poly-time algorithm to verify a particular solution. ... My student was working as a software developer and he was meeting ...
    (comp.theory)
  • Re: PRINTING DIAMOND SHAPE WITH LOOPS!
    ... > stereotypes. ... Neither unfair nor a stereotype. ... falsely not to be a student, while explaining what kind of student you are. ... deterministic algorithm like this. ...
    (comp.lang.java.programmer)
  • Re: "Sorting" assignment
    ... algorithm such as tbe bubble sort should be given a free pass because ... I would tailor which algorithm to start with by how the student thinks ... If you only learn the beautiful side of programming, ...
    (comp.programming)
  • RE: No clue whatsoever, so thought Id ask the experts
    ... increase the Dim to match the number of questions ... Gary''s Student - gsnu2007L ... "Paul" wrote: ... thing) to prompt a window to pop up with a Label "What is ...
    (microsoft.public.excel.programming)
  • RE: No clue whatsoever, so thought Id ask the experts
    ... Gary''s Student - gsnu2007L ... "Paul" wrote: ... to which I woudl type the data/answer. ... thing) to prompt a window to pop up with a Label "What is ...
    (microsoft.public.excel.programming)

Loading