954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help!!! (stupid java question)

import java.util.*;

public class SelectSort
{
    // instance variables - replace the example below with your own
    public int x;
    public ArrayList<Integer> a;
    public int n;
    
    public SelectSort(int b)
    {
        a = new ArrayList<Integer>() ; 
        n = a.size();
        for(int i = 1; i < n; i++)
        {
            SortNow(); //tried everything and the call isn't working

            
        }
    }
    
    private int SortNow(int[] a,int i, int n)
    {
        int small = i;
        for(int j = i; i < n; i++)
        {
            if(a[j] < a[small])
            {
                small = j;
            }
        }
        return small;
    }
}

//I know this looks simple but I'm a beginner :).

yazz110
Newbie Poster
18 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

1) Use code Tags
2)SortNow(); // No paramater
3)private int SortNow(int[] a,int i, int n) // Three Paramter

You are calling a function which dont exist...
Pass paramters or make empty paramter function.

Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
 
public class SelectSort
{
    // instance variables - replace the example below with your own
    public int x;
    public ArrayList<Integer> a;
    public int n;
    
    public SelectSort(int b)
    {
        a = new ArrayList<Integer>() ; 
        n = a.size();
        for(int i = 1; i < n; i++)
        {
            SortNow(int[] w, int n); // says '.Class' expected.
            //Know I stupid but I'm new at this
        }
    }
    
    public int SortNow(int[] a,int i)
    {
        int small = i;
        for(int j = i; i < n; i++)
        {
            if(a[j] < a[small])
            {
                small = j;
            }
        }
        return small;
    }
}
//Don't know what to do
yazz110
Newbie Poster
18 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

1) Use Code Tags [code] Code here [/code]

2) for(int i = 1; i < n; i++)
{
SortNow(int[] w, int n); 
} 
// dont u know how to pass paramter to function

3) Have u imported java.util.ArrayList; for Array List

4) We all make blunder's when we try new things, it isnt stupidity, that what call learning , but before starting try to read books so you can fully use your brain cells at time of coding.

Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
 

I already imported arraylist. Thing is sometimes I'm good at this but sometimes I'm absolute rubbish (and this is one of those times.), and you are right my brain cells at this time are dead.

yazz110
Newbie Poster
18 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 
Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
 

Thanks :). I owe you one.

yazz110
Newbie Poster
18 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

Very simple solution, get an IDE that error checks. I recommend Eclipse or NetBeans. I personally use Eclipse and threw your code into a new class and it found several errors that have not yet been addressed.

Also one error that eclipse will not catch because it cannot catch Intention errors nor fallacies:

SortNow(int[] w, int n); // several errors, I'll let Eclipse and Google explain them to you.

//Intention error located in piece below, started in the line above

public int SortNow(int[] a,int i) // i initialized to global n
    {
        int small = i; // small initialized to i which = n
        for(int j = i; i < n; i++) // j initialized to i which = n, i = n therefore i will never be < n, newly initialized j ignored and not incremented nor compared to anything so it will always = n
        {
            if(a[j] < a[small]) // never true... j will always = n = small
            {
                small = j; // they already equal one another so...
            }
        }
        return small; // you basically returned n...
    }
Arrorn
Light Poster
40 posts since Mar 2009
Reputation Points: 7
Solved Threads: 5
 

IDE dont catch logical errors. Above is a logical error.

tick
Newbie Poster
2 posts since Jun 2011
Reputation Points: 15
Solved Threads: 1
 

Thanks a lot :), I actually re-wrote the code and worked on it all day. It works better now but I still have a lot to add to it. Thanks for your advice, I'm using BlueJ :P not really the best in the world but sort of forced to use it. Thanks for point out all the mistakes as well :D. I'm a silly programmer hopefully I get better at code :).

yazz110
Newbie Poster
18 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: