A Java method for reading rows and columns?

  • Java
  • Thread starter Redd
  • Start date
  • #1
47
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 lets you read the number of rows and columns from your previous OUTPUT?
 

Answers and Replies

  • #2
3
0
plz specify your question,,,r u gonna take the number of rows and columns from the user?
if not ,what do u mean by previous output
 
  • #3
47
0
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...
 
  • #4
Hurkyl
Staff Emeritus
Science Advisor
Gold Member
14,916
19
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?)
 
  • #5
47
0
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....
 
  • #6
Hurkyl
Staff Emeritus
Science Advisor
Gold Member
14,916
19
Can you describe part of the program you need to write in Java, with the rest of it in English?
 
  • #7
47
0
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.
 
  • #8
Hurkyl
Staff Emeritus
Science Advisor
Gold Member
14,916
19
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.
 
  • #9
378
2
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
47
0
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!
 

Related Threads on A Java method for reading rows and columns?

Replies
2
Views
2K
  • Last Post
Replies
2
Views
2K
Replies
2
Views
897
  • Last Post
Replies
1
Views
2K
Replies
2
Views
2K
  • Last Post
Replies
3
Views
6K
  • Last Post
Replies
1
Views
2K
Replies
1
Views
2K
Replies
1
Views
4K
Top