Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Members have full access to the forums. Advertisements are removed for registered users.

# Thread: Help with beginner code

1. ## Help with beginner code

Hi, My child is appearing for class x exams and is having difficulty with java programming. Is writing different programs but is having difficulty understanding where is going wrong. Can someone please look at this code to sort 15 numbers in descending order using selection sort

//program to accept 15 numbers and print them in descending order using selection sort
import java.io.*;
public class sort
{
public static void main(String[]args)throws IOException
{
BufferedReader userin= new BufferedReader(new InputStreamReader(System.in));
int i;int j;int pos;int max;int t; //
int n[]=new int[15];
for(i=0;i<15;i++)
{
System.out.println("Enter a number");
n[i]=Integer.parseInt(userin.readLine());
}

for(i=0;i<14;i++);
{
max=n[i];
pos=i;

for(j=i+1;j<15;j++);
{
if(n[i] < n[j])
n[j]=max;
pos=j;
}

}

t=n[i];
n[i]=n[pos];
n[pos]=t;
for(i=0;i<15;i++)
{
System.out.println(n[i]);

}
}
}

2. ## Re: Help with beginner code

Try to post code in a formatted way so we can see what's going on.

One error that jumps out is this:
for(j=i+1;j<15;j++);
{
//do something
}

The semi-colon will end the for loop right there and it won't do what's in the curly brackets.

3. ## Re: Help with beginner code

Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.

Also format the code with proper indentations to show logic nesting levels.