How do you increment arrays in for loops?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2007
Posts: 29
Reputation: Monyet is an unknown quantity at this point 
Solved Threads: 0
Monyet's Avatar
Monyet Monyet is offline Offline
Light Poster

How do you increment arrays in for loops?

 
0
  #1
Feb 20th, 2007
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..

  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...
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How do you increment arrays in for loops?

 
0
  #2
Feb 20th, 2007
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: How do you increment arrays in for loops?

 
0
  #3
Feb 21st, 2007
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 39
Reputation: MacGyver Orca is an unknown quantity at this point 
Solved Threads: 4
MacGyver Orca's Avatar
MacGyver Orca MacGyver Orca is offline Offline
Light Poster

Re: How do you increment arrays in for loops?

 
0
  #4
Feb 21st, 2007
Why don't you just include a print statement inside the for loop where you assign the random values?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3072 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC