Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Tolls

Thread: Need help

  1. #1
    woodanthony is offline Member
    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Default Need help

    I'm getting error: class, interface or enum messages some one please tell me what I'm doing wrong?

    import java.util.ArrayList;
    import java.util.Scanner;

    public class Ch11Lab3
    {
    public static void main(String[] args)
    {
    Scanner input = new Scanner(System.in);

    ArrayList<Integer>list = new ArrayList<Integer>();

    System.out.println("Enter five integers:");
    for(int i = 0; i < 5; i++)
    list.add(input.nextInt());

    sort(list);

    for(int i=0; i<list.size(); i++)
    System.out.println(list.get(i) + " ");

    public static void sort(ArrayList<Integer>list){
    for(int i=0; i<list.size() -1; i++){
    //Find the minimum in the list[i..list.length-1]
    int currentMin = list.get(i);
    int currentMinIndex = i;
    }
    }


    for(int j=i+1; j>list.size(); j++){
    if(currentMin > list.get(j)){
    currentMin = list.get(j);
    currentMinIndex = j;
    }
    }


    //Swap list with list.get(currentMinIndex) if necessary;
    if(currentMinIndex !=i){
    list.set(currentMiIndex, list.get(i));
    list.set(i, currentMin);
    }
    }
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Need help

    Please post the full error text, highlighting the line(s) on which they occur.
    Also please wrap your code in [code] tags [/code] so it retains its formatting.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    viren2727in is offline Member
    Join Date
    Jan 2013
    Location
    INDIA
    Posts
    18
    Rep Power
    0

    Default Re: Need help

    Hi woodanthony,

    Please find array sorting code as under

    Java Code:
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Scanner;
    
    public class Ch11Lab3 {
        
    	public static void main(String[] args) {
    		
    		Scanner input = new Scanner(System.in);
    
    		ArrayList<Integer>list = new ArrayList<Integer>();
    
    		System.out.println("Enter five integers:");
    		for(int i = 0; i < 5; i++)
    			list.add(input.nextInt());
    
    		Collections.sort(list);
    
    		for(int i=0; i<list.size(); i++)
    			System.out.println(list.get(i) + " ");
    
    	}
    }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Need help

    1. You shouldn't provide outright solutions.
    2. I think the OP is supposed to write the sort code themselves?
    SurfMan likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Posting Permissions

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