• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array int print  RSS feed

 
Pat Steele
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



I apologize for not putting this into the easy read thing. If an admin can convert it I would appreciate it.

Is there a way to write this, where, alpha is one array.

The professor I have now gave us a sub-standard book with no real resource to learn the material. Except for a really really substandard set of powerpoints which was about the most informative piece she gave us. That said, she is a very bad teacher.

Write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.

Have at it, and thanks

If I have an array of 50 integers, can I break that to read in lines of 10?
 
Jude Niroshan
Ranch Hand
Posts: 132
5
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pat,
Implement the logic which you applied to get those values in those 4 arrays, inside a loop and put them to a single double array at the end of an each iteration. When you print them, just use loops. I don't think she will be considering about performance aspect.
Regards,
Jude
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have an array of 50 integers, can I break that to read in lines of 10?

You can use System.out.print() method for printing set of 10 values. And then use System.out.println() statement to change the line
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Steele wrote:Write a program that declares an array "alpha" of 50 elements of type "double".


Well, at the moment you don't have such an array with 50 elements in it. Instead, you have 5 arrays, where each contains by 10 elements.
Try to follow requirements, otherwise I can assume it's wrong straight away.

One more thing, try to stop coding at this stage, even these lines:


makes the problem more confusing, as more than half of them are not needed now neither at a later stage.

Try to think about the problem in your head first.
And 1st task probably should be, how to create and array based on given requirements (avoiding manual input of 50 elements).
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for not putting this into the easy read thing. If an admin can convert it I would appreciate it.


If you UseCodeTags (← click) your code will be displayed formatted. You can also edit your own posts so you can add them yourself.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liutauras Vilda wrote: . . .
Well, at the moment you don't have such an array with 50 elements in it. Instead, you have 5 arrays, where each contains by 10 elements.
Try to follow requirements, otherwise I can assume it's wrong straight away.
. . . (avoiding manual input of 50 elements).
Your program is supposed to populate the arrays by itself; don't try to populate them by hand.
 
Pat Steele
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here again is the required assignment. Nothing posted here helps me except the recomendation that I use a for loop. Again the book is a reference type book meant to be a complement to an actual lecture. The lecture does not happen... being an online "taught" class.

I appreciate the feedback, but I am looking for a step by step code example with // notes
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Steele wrote:Here again is the required assignment. Nothing posted here helps me except the recomendation that I use a for loop. Again the book is a reference type book meant to be a complement to an actual lecture. The lecture does not happen... being an online "taught" class.

I appreciate the feedback, but I am looking for a step by step code example with // notes

Well, how would you do this first step: Write a program that declares an array "alpha" of 50 elements of type "double". Give it a shot and show us what you've done.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Steele wrote:Nothing posted here helps me except the recomendation that I use a for loop.
I appreciate the feedback, but I am looking for a step by step code example with // notes


Pat, I'm afraid it is not the way we understand the learning process. All guys here are very happy to help, in fact, believes that exact answers or precise examples of the problem doesn't make you think.

Hint:you should try to simplify the given problem into smaller tasks.
First task as you've been suggested already, should encourage you to think, how to create "an array "alpha" of 50 elements of type "double"."

Take this as a very good advice:
Campbell Ritchie wrote:Your program is supposed to populate the arrays by itself; don't try to populate them by hand.

So in order to achieve that, you'll need to use loop, likely "for".

Try to come up with something, and post it here once you get.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Steele wrote:I appreciate the feedback, but I am looking for a step by step code example with // notes

Sorry, but that's not how we do things around here. We encourage students to do their own homework. We simply provide advice, tips, guidance. We understand that it can be a bit overwhelming for a beginner but we also believe the best way to learn is by doing it yourself.

Here's what you have been given so far:
1. Don't populate the array manually as you have now
2. Use for loops
3. Use System.out.print and System.out.println

These alone are enough hints to complete your assignment.

As for your resources or lack thereof, you have the Internet at your fingertips.Here are a few search terms you can use to find examples galore:
java example how to initialize arrays
java for loop examples

And if you have an issue with how your professor presents her materials, it's better to go to her and discuss your difficulties rather than complain in a public forum like this one; you never know who's going to end up reading your posts.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The modulus operator, %, will come in handy when printing 10 numbers on each line. Search for java modulus operator to control batch size
 
Pat Steele
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Well enough. I do thank you for this input. I think I can work it out now.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Do show us the finished product so we can admire it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!