Results 1 to 2 of 2
  1. #1
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    120
    Rep Power
    0

    Exclamation Cofused with java for loop methods I've made

    Java Code:
    public String[] getPreLayers() {
    		int lCount = 0;
    		for (int i = 0; i < mENTPRIOR; i++) { lCount++; }
    		String[] preLayers = new String[lCount];
    		for (int i = 0; i < mENTPRIOR; i++) { preLayers[i] = nLayers[i]; }
    		return preLayers;
    		
    	}
    	public String[] getPostLayers() {
    		String[] postLayers = {};
    		for (int i = mENTPRIOR + 1; i < nLayers.length; i++) {
    			postLayers[i - mENTPRIOR - 1] = nLayers[i];
    		}
    		return postLayers;
    	}
    So let's say mENTPRIOR = 5;
    nLayers.length = 10;
    nLayers = {"s","s","s","s","s","s","s","s","s","s"}

    getPreLayers() should return a list of the first 5 "s"s
    getPostLayers() should return a list of the next 5 "s"s

    So like break up the array at point 5. So the ten is seperated into 1 array of 5s and another array of 5s, how chould I change my code to make this work? Really confusing because I'm working with nLayers.length = 2, which is really small. This method must also work with 1, where let's say ENTPRIOR is 1, and it will make preLayers.length = 1, postLayers.length = 0. Help! P:

    Thanks
    Augustas

  2. #2
    augustas656 is offline Senior Member
    Join Date
    Apr 2014
    Location
    United Kingdom
    Posts
    120
    Rep Power
    0

    Default Re: Cofused with java for loop methods I've made

    Problem fixed, if anyone would have the same problem, I initialised the PostLayers array with nothing, and when it tried doing postLayers[0] it got an error.

Similar Threads

  1. Replies: 7
    Last Post: 10-14-2012, 06:05 AM
  2. Java Programs I Made
    By imsoadude in forum Reviews / Advertising
    Replies: 0
    Last Post: 08-24-2012, 02:39 AM
  3. Replies: 7
    Last Post: 01-20-2012, 11:29 AM
  4. Use a dll made in .net (C#) COM Visible within JAVA
    By ealopez26 in forum Advanced Java
    Replies: 6
    Last Post: 09-16-2011, 04:46 AM
  5. Loop with several methods
    By joshft91 in forum New To Java
    Replies: 13
    Last Post: 11-11-2010, 09:08 AM

Posting Permissions

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