Results 1 to 2 of 2
  1. #1
    cassysumandak is offline Member
    Join Date
    Mar 2009
    Posts
    38
    Rep Power
    0

    Default Problem printing inside FOR loop

    Hi, I have problem printing inside the FOR loop.
    After the first two FOR loop, this method stop reading the next line. How can I solve this problem. This is strange.

    Java Code:
    	private int spacing() {
    		int n = numberOfTriangles();
    		
    		ArrayList<Double> list_Xs1 = new ArrayList<Double>(); 
    		ArrayList<Double> list_Ys1 = new ArrayList<Double>(); 
    
    		for(Polygon p:triangles){
    			double cX = p.xpoints[0];
    			double cY = p.ypoints[2];
    			list_Ys1.add(cY);
    			list_Xs1.add(cX);
    		}
    
    		//Remove duplicate key in X	
    		HashSet<Double> hashSet_list_Xs1= new HashSet<Double>(list_Xs1);
    		ArrayList<Double> list_Xs2	= new ArrayList<Double>(hashSet_list_Xs1);
    		Collections.sort(list_Xs2);
    
    		//Remove duplicate key in Y	
    		HashSet<Double> hashSet_list_Ys1= new HashSet<Double>(list_Ys1);
    		ArrayList<Double> list_Ys2	= new ArrayList<Double>(hashSet_list_Ys1);
    		Collections.sort(list_Ys2);
    				
    		ArrayList<Double> list_Xs3 = new ArrayList<Double>(); 
    		ArrayList<Double> list_Ys3 = new ArrayList<Double>(); 
    		double distanceX = 0.0,distanceY=0.0;
    
    		//Get Distance between X coordinate
    		for (int j=0; j<list_Xs2.size(); j++){
    			distanceX = Math.abs(list_Xs2.get(j) - list_Xs2.get(j+1));
    			list_Xs3.add(distanceX);
    			System.out.println("I am able to print everything inside this loop");
    		}
    		
    		System.out.println("This is not printed");
    
    		//Get Distance between Y coordinate		
    		for (int i=0; i<list_Ys2.size(); i++){
    			distanceY = Math.abs(list_Ys2.get(i) - list_Ys2.get(i+1));
    			list_Ys3.add(distanceY);
    			System.out.println("Nothing printed in this loop");
    		}
    
    		//Remove duplicate key in Y	
    		HashSet<Double> hashSet_list_Ys2= new HashSet<Double>(list_Ys3);
    		ArrayList<Double> list_Ys4 	  	= new ArrayList<Double>(hashSet_list_Ys2) ;
    		
    		//Remove duplicate key in X	
    		HashSet<Double> hashSet_list_Xs2 = new HashSet<Double>(list_Xs3);
    		ArrayList<Double> list_Xs4 	  = new ArrayList<Double>(hashSet_list_Xs2) ;
    		
    		int distinctDistance_Xs = list_Xs4.size(); 
    		int distinctDistance_Ys = list_Ys4.size(); 
    
    		
    		int nSpacing = distinctDistance_Xs + distinctDistance_Ys;
    
    		int RMspacing=0;
    		if (n==1)
    			RMspacing = 1;
    		else if (n != 1)
    			RMspacing = 1 - ((nSpacing-1)/(2*(n-1)));
    		
    		return RMspacing;
    	}

  2. #2
    cassysumandak is offline Member
    Join Date
    Mar 2009
    Posts
    38
    Rep Power
    0

    Default

    never mind..I solved the problem by adding -1

    Java Code:
    for (int j=0; j<list_Xs2.size()-1; j++){
    ....
    }
    for (int i=0; i<list_Ys2.size()-1; i++){
    ....
    }

Similar Threads

  1. Inside a Timer thread loop,how to refresh a JTable in swing
    By neha_negi in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-04-2009, 02:45 AM
  2. Replies: 9
    Last Post: 07-21-2009, 03:41 AM
  3. println doesn't print from inside for loop, et.al.
    By rdtindsm in forum New To Java
    Replies: 5
    Last Post: 03-27-2009, 02:19 PM
  4. problem aligning both image/text inside a button
    By rick_cols in forum SWT / JFace
    Replies: 0
    Last Post: 09-18-2008, 09:20 PM
  5. printing problem
    By ntpl in forum AWT / Swing
    Replies: 0
    Last Post: 11-27-2007, 12:20 PM

Tags for this Thread

Posting Permissions

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