Results 1 to 4 of 4
  1. #1
    ssk2659 is offline Member
    Join Date
    Jan 2015
    Posts
    48
    Rep Power
    0

    Default For loop involving array

    As a result I need to get 6 66 666 6666 66666, but I'm getting a mistake. Can anb explain what's wrong?
    Java Code:
    public static void main(String [] args)
    	{
    		
    		int[] sixes = new int [6];
    		for (int i = 0; i < sixes.length; i++)
    		{
    			sixes[i] = i * 10 + 6;
    			
    			System.out.print(sixes[i]);
    			
    		}
     
    		
    	}
    Last edited by ssk2659; 01-30-2015 at 12:24 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: For loop involving array

    Why are you using an array? And what about v? You need to think thru the process on paper.

    Suppose v = 6. You print it. Now how to you make v = 66? And then how to you make v = to 666?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    ssk2659 is offline Member
    Join Date
    Jan 2015
    Posts
    48
    Rep Power
    0

    Default Re: For loop involving array

    My bad for v there, I have to fill out the array {6, 66, 666, 6666, 66666}

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: For loop involving array

    Then try what I said. But assign each change of v to the next array element.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 3
    Last Post: 12-28-2013, 10:39 PM
  2. Replies: 5
    Last Post: 03-29-2012, 07:22 PM
  3. Replies: 1
    Last Post: 10-01-2011, 03:12 AM
  4. Loop through Array in JSP
    By Robert_85 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-25-2010, 10:00 PM
  5. Replies: 5
    Last Post: 02-25-2009, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •