Results 1 to 1 of 1

Thread: Java

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Eclipse Plugin Developer aphex's Avatar
    Join Date: Mar:2003
    Location: Karlsruhe
    Posts: 546

    Question Java

    ,
    , java.lang.StringIndexOutOfBoundsExceptio n: String index out of range: 5.

    :
    Code:
    import java.io.*;
    
    public class SortAndCalculate  {
    	public static void main (String args[])throws IOException {
    		FileReader inFile = new FileReader("output.txt"); 
    	    BufferedReader in = new BufferedReader(inFile); 
    	    String c[]= new String[5162];
    	    String line;
    	    int i=0;
    	    while((line = in.readLine()) != null){
    	    	
    	    	c[i]=line;
    	    	i++;
    	    }
    	    c=sortStringArray(c);
    	}
    	
    	static String[] sortStringArray( String in[]){
    		boolean vertauscht=false;
    		boolean isgreater = false;
    		int n=in.length;
    		do{
    			vertauscht = false;
    			for(int i=1;i<n-1;i++){
    				for(int p=1;p<in[i].length()-1;p++){
    					if(in[i].charAt(p)>in[i+1].charAt(p)){
    						isgreater=true;
    						vertauscht = true;
    					}
    					else isgreater=false;
    				}
    				if (isgreater){
    					String buffer =in[i];
    					in[i]=in[i+1];
    					in[i+1]=buffer;
    				}
    				
    			}
    			n=n-1;
    		}while(n>=1 && vertauscht);
    	return in;
    	}
    }

    java.util .. Arrays.sort();
    , .
    Last edited by aphex; 12th May 2008 at 02:17.
    We are drowning in information, but starving for knowledge and time!

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |