Hi evryone! :)
I'm a complete beginner in Java and today i'm found my self stack while trying
to solve a problem. Basically what i have to do is to write a program that sorts three integers.
The integers are entered from the input dialogs and stored in variables num1, num2, and num3,
respectively. The program sorts the numbers so that num1 <= num2 <= num3. I tryed everything i can,

But first of all you have to post what you have done so far?

First post where have you been stuck in your program?

OK. All it takes to get a program is a little research and modification of the program to suit your needs. I found a program on the web and modified it for user's input. Here's the program, hope it helps.

PS: I am also new to Java, one year, but I research, learn, try, and ask for help. That's what helped me increase my ability to code in Java.

``````import static java.lang.System.*;
import java.util.Scanner;

class OrderPlacement3 {

public static void main(String[] args) {
int num1, num2, num3;

//Gets the users input
Scanner input = new Scanner(System.in);
out.print(" Enter first number    ===>> ");
num1 = input.nextInt();
out.print(" Enter second number   ===>> ");
num2 = input.nextInt();
out.print(" Enter third number    ===>> ");
num3 = input.nextInt();
out.println();

//Without using Arrays.sort function
int i;
int nos[] = {num1, num2, num3};
sort(nos, nos.length);
System.out.print("Values after sorting: \n");
for(i = 0; i <nos.length; i++){
System.out.println(nos[i]+"  ");
}
}

private static void sort(int nos[], int n) {
for (int i = 1; i < n; i++){
int j = i;
int B = nos[i];
while ((j > 0) && (nos[j-1] > B)){
nos[j] = nos[j-1];
j--;
}
nos[j] = B;
}
}
}
``````

if you are new to Java, don't just copy paste some code you've
"found [a program] on the web"

write your own. a sorting algorithm is pretty basic and very easy.
go step by step.
write a small piece of pseudo code and implement that.

Start4Me: never just provide custom code, give them a chance to work on it themselves.

I research, learn, try, and ask for help. That's what helped me increase my ability to code in Java.

Yes, absolutely right.
But how does this fit with your posting a complete undocumented uncommented solution that the OP can just copy/paste without any understanding? I hope in your future posts you will prefer to help and guide the OP so they can laern how to solve the problem for themself

Thank you stultuske and JamesCherrill for advice. I will take that as a lesson, however, when I got stuck in the past and asked for help, those who tried to help me by posting "a small piece of pseudo code", never actually helped me, rather got me more confused. What approach could be more helpful is providing a "pseudo code" with a commentary on where to implement the code in the program, rather than giving a code that won't resolve the program completely.

you can't hold starters by the hand.
have you told those that you didn't understand the pseudocode, and wanted some additional explanation? it's impossible for those who try to help you to know what level of experience/knowledge you are.
sometimes it is better to not immediately understand the help given, and do some additional investigation yourself.