Java Solve Java Selection Sort Issues | Hi, I'm Working on Code

  • Thread starter Thread starter tshet
  • Start date Start date
  • Tags Tags
    Java Sort
AI Thread Summary
The discussion revolves around issues encountered while implementing selection sort in Java. The user shares their code, which is intended to sort an array but fails to compile due to several errors. Key problems identified include the incorrect use of the array variable 'a', which is not properly initialized or referenced, leading to compilation issues. The user acknowledges that they based their selection sort structure on a bubble sort implementation, indicating a potential misunderstanding of the selection sort algorithm. Other participants emphasize the importance of providing specific error messages from the compiler to diagnose the issues effectively. They suggest that without clear indications of the errors, it's challenging to provide accurate assistance. The conversation highlights the need for clarity in coding practices and debugging processes.
tshet
Messages
2
Reaction score
0
Hi, I'm currently working on my selection sort code, and I've come across some problems.

Java:
i
import java.util.Arrays;
import java.io.*;

public class SelectionSort
{
int a[];
static int n;

public static void main(String[] args)
{
int array[] = { 5,3,9,7,1,8 };
n = 6;
System.out.println(""+Arrays.toString(Sort(array)));
}

public static int[] Sort(int[] arr)
{
int t, min;
for(int i=0;i<n-1;i++)
{
min = i;
for(int j=i+1;j<n;j++)
{
if(a[min]>a[j])
min = j;
}
if(min!=i)
{
t = a[min];
a[min] = a;
a = t;
}
System.out.println(""+Arrays.toString(arr));
}
return arr;
}

}

Can someone please tell me what the problem is?
 
Last edited by a moderator:
Technology news on Phys.org
What have you tried so far and what do you think is wrong?
 
Well, I've taken the structure of my bubble sort and put it into my selection sort. I'm just trying to change the code for the actual selection part. I'm just getting simple mistakes now..
 
It's doubt that it's that easy. I put the code in my IDE and it highlights several problems such that it won't compile. What's the error that you're getting when you try to compile?
 
tshet said:
Can someone please tell me what the problem is?
It's difficult for us to say what the problem is merely by looking at your code. Make it easier by giving us a clue about what you're seeing? Are you getting compile errors? (Another poster in this thread said that your code doesn't compile.) If it doesn't compile, what error message is the compiler giving you?

If the code compiles but throws and exception or otherwise doesn't behave like it should, give us that information, and in fact, any information that would help us help you.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Back
Top