Java A Java method for reading rows and columns?

AI Thread Summary
The discussion revolves around creating quarter diamond patterns in Java using loops, with a focus on managing the number of rows and columns based on user input. The original poster expresses confusion about how to track the number of stars printed while adhering to the requirement of using a single print statement. They seek clarification on whether there is a method to read the number of rows and columns from previous output, indicating a misunderstanding of how to manage loop variables effectively. Participants suggest that the values for rows and columns can be retained and updated within the loop itself, rather than trying to read them from output. The poster realizes that they were overcomplicating the task and acknowledges that they can declare and increment the row and column counters within the loop structure. This insight leads to a more straightforward approach to solving the assignment, emphasizing the importance of clear logic and direction in programming. The conversation highlights the challenges faced by beginners in programming, particularly in articulating and implementing logical steps in code.
Redd
Messages
47
Reaction score
0
I have an assignment where we have to use loops to print quarter diamond patterns.

I don't really need help with the actual coding, since the prof basically gave us a pseudo-code as a hint, but in the pseudo-code there is a variable for the number of rows and columns.

I have been searching the Java API but its hard to wade through without having a better sense of what you are looking for.

So my big question is:

Is there a method that let's you read the number of rows and columns from your previous OUTPUT?
 
Technology news on Phys.org
please specify your question,,,r u going to take the number of rows and columns from the user?
if not ,what do u mean by previous output
 
Yes, in hindsight I was a little vague.

The pattern we have to make is like this:
*
**
***
...
continuing to a specific number of stars input by the user.
But the professor wants us to use only a single print statement, while creating the rest of the pattern by looping it.

But the way he seems to be implying we do it requires that you know how many stars have already been printed. He refers to this variable as num-row, or num-column.
I am just confused how I could get these values because I am not aware of a method like that. I need them to tell the code when to stop running (i.e. when the number of rows equals the width specified by the user).

Thanks for any help, if this makes sense...
 
Redd said:
I am just confused how I could get these values
You already had these values. If you need them again, then don't forget them. (You needed them to print the previous row, right?)
 
Hurkyl said:
You already had these values. If you need them again, then don't forget them. (You needed them to print the previous row, right?)

I think it would be better if I phrased the question outside of the context of my professor's hints.

I guess what I am really confused on is how to quantify the number of stars while still having a single print statement.

In order to use a loop I need a condition to be met that uses numbers. I cannot think of a way to have a variable that represents the number of stars being printed, and therefore I don't have a way of checking if certain conditions are being met (like the width equaling the user's input.)

haha sorry if this is not making sense. I actually am becoming increasingly unaware as to how this can be done...
 
Can you describe part of the program you need to write in Java, with the rest of it in English?
 
Hurkyl said:
Can you describe part of the program you need to write in Java, with the rest of it in English?

Okay. Well I just typed a whole big thing about what I thought was workable pseudocode for this but I quickly realized that when I went through and followed the directions I was giving the computer, I was not getting the pattern. So, yeah, I need to start from scratch and just see how I want the logic to go with this.

But thanks for making me try it in English. I should probably be able to explain it to myself before I can hope to explain it to a computer :P.

I am very new to programming and I don't really have a brain for it I suppose.
 
Following directions is difficult: giving directions even more so. Not because they are inherently difficult, but because we spend most of our lives being quite vague about things.

This is probably the first time you are exposed to the problem of writing clear and precise directions, and the computer is very unforgiving -- it will do exactly what you tell it to do, and it will not fill in any little details you forgot to specify.

e.g. it won't "just know" how to remember where it is in the diagram -- you have to explicitly tell it how to remember.
 
public void Main(String [] args)
{

int num = 0;

..

num = 45;
System.out.println("num is currently 45");

...

System.out.println("What was the num value?");
System.out.println("value is "+num);//45

..
}
 
  • #10
Thanks rootx but I meant reading the value as in the number of characters or something...um?

I'm not sure. I was just being silly. Regardless.

I realized that I can declare column and row integers in the first part of a for statement then add one to them after each iteration.

I was seriously overcomplicating it, because I was trying to actually monitor the value of the columns and rows as they grew but I can just keep them in the loops.

I'm not sure if that makes sense but it feel like I can make it work.

If I have more trouble I will come back, but, thanks!
 
Back
Top