944,010 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 5406
  • Java RSS
Feb 20th, 2007
0

How do you increment arrays in for loops?

Expand Post »
How do you do this? I can assign each random values into arrays, but I cannot increment the value so that I can display each values with another for loops. It needs to be 5 to the right..

java Syntax (Toggle Plain Text)
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. public class LabAssgn_laksmono
  4. {
  5. public static void main(String args[])
  6. {
  7. Scanner input = new Scanner(System.in);
  8. Random r = new Random();
  9. int user;
  10. do
  11. {
  12. System.out.print("Enter input between 10 to 100: ");
  13. user = input.nextInt();
  14. }
  15. while(user > 100 || user < 10);
  16. int array[] = new int [user];
  17. int values;
  18. for(int i = 0 ; i < array.length ; i++)
  19. {
  20. values = r.nextInt(100) + 1;
  21. array[i] = values;
  22. for (int j = 1; j <= 5; j++)
  23. {
  24. System.out.printf("%d ", values);
  25. }
  26. System.out.println();
  27. }
  28. }
  29. }

thanx for the help...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Monyet is offline Offline
29 posts
since Feb 2007
Feb 20th, 2007
0

Re: How do you increment arrays in for loops?

WHAT can't you do?
Either you don't know what you're trying to do or you can't explain it to someone else.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Feb 21st, 2007
0

Re: How do you increment arrays in for loops?

Please explain what you expect to see as output, and what you are seeing as output, as well as what was provided as input.

Also, post any exceptions you may be getting.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Feb 21st, 2007
0

Re: How do you increment arrays in for loops?

Why don't you just include a print statement inside the for loop where you assign the random values?
Reputation Points: 19
Solved Threads: 4
Light Poster
MacGyver Orca is offline Offline
39 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Card Game Help
Next Thread in Java Forum Timeline: Wireless information sharing system





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC