title: How to Sort Numbers with If Statements (Java)
body: <p>I know that you can easily sort numbers with an array, but my assignment for class is that I need to sort four numbers in descending order using <strong>if statements</strong> and <strong>not arrays</strong>.</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>package integersort;
  
  import java.util.Scanner;
  
  public class IntegerSort {
  
  public static void main(String[] args) {
      Scanner userInput = new Scanner(System.in);
  
      int firstNum, secondNum, thirdNum, fourthNum; //inputted numbers
  
      System.out.println("Enter first number:");
      firstNum = userInput.nextInt();
      System.out.println("Enter second number:");
      secondNum = userInput.nextInt();
      System.out.println("Enter third number:");
      thirdNum = userInput.nextInt();
      System.out.println("Enter fourth number:");
      fourthNum = userInput.nextInt();
  
  
      int firstPlace = 0, secondPlace = 0, thirdPlace = 0, fourthPlace = 0;
  
      //firstPlace start
      if (firstNum &gt; secondNum &amp;&amp; firstNum &gt; thirdNum &amp;&amp; firstNum &gt; fourthNum) {
          firstPlace = firstNum;
      } else if (secondNum &gt; firstNum &amp;&amp; secondNum &gt; thirdNum &amp;&amp; secondNum &gt; fourthNum) {
          firstPlace = secondNum;
      } else if (thirdNum &gt; firstNum &amp;&amp; thirdNum &gt; secondNum &amp;&amp; thirdNum &gt; fourthNum) {
          firstPlace = thirdNum;
      } else if (fourthNum &gt; firstNum &amp;&amp; fourthNum &gt; secondNum &amp;&amp; fourthNum &gt; thirdNum) {
          firstPlace = fourthNum;
      }
      //firstPlace end
  
      //fourthPlace start
      if (firstNum &lt; secondNum &amp;&amp; firstNum &lt; thirdNum &amp;&amp; firstNum &lt; fourthNum) {
          fourthPlace = firstNum;
      } else if (secondNum &lt; firstNum &amp;&amp; secondNum &lt; thirdNum &amp;&amp; secondNum &lt; fourthNum) {
          fourthPlace = secondNum;
      } else if (thirdNum &lt; firstNum &amp;&amp; thirdNum &lt; secondNum &amp;&amp; thirdNum &lt; fourthNum) {
          fourthPlace = thirdNum;
      } else if (fourthNum &lt; firstNum &amp;&amp; fourthNum &lt; secondNum &amp;&amp; fourthNum &lt; thirdNum) {
          fourthPlace = fourthNum;
      }
      //forthPlace end
  
      //secondPlace start
      if (firstNum != firstPlace &amp;&amp; firstNum != fourthPlace &amp;&amp; firstNum &lt; firstPlace &amp;&amp; firstNum &gt; fourthPlace &amp;&amp; firstNum &gt; fourthNum) {
          secondPlace = firstNum;
      } else if (secondNum != firstPlace &amp;&amp; secondNum != fourthPlace &amp;&amp; secondNum &gt; firstNum &amp;&amp; secondNum &gt; thirdNum &amp;&amp; secondNum &gt; fourthNum) {
          secondPlace = secondNum;
      } else if (thirdNum != firstPlace &amp;&amp; thirdNum != fourthPlace &amp;&amp; thirdNum &gt; firstNum &amp;&amp; thirdNum &gt; secondNum &amp;&amp; thirdNum &gt; fourthNum) {
          secondPlace = thirdNum;
      } else if (fourthNum != firstPlace &amp;&amp; fourthNum != fourthPlace &amp;&amp; fourthNum &gt; firstNum &amp;&amp; fourthNum &gt; secondNum &amp;&amp; fourthNum &gt; thirdNum) {
          secondPlace = fourthNum;
      }
      //secondPlace end
  
      //thirdPlace start
      if (firstNum != firstPlace &amp;&amp; firstNum != secondPlace &amp;&amp; firstNum != fourthPlace) {
          thirdPlace = firstNum;
      } else if (secondNum != firstPlace &amp;&amp; secondNum != secondPlace &amp;&amp; secondNum != fourthPlace) {
          thirdPlace = secondNum;
      } else if (thirdNum != firstPlace &amp;&amp; thirdNum != secondPlace &amp;&amp; thirdNum != fourthPlace) {
          thirdPlace = thirdNum;
      } else if (fourthNum != firstPlace &amp;&amp; fourthNum != secondPlace &amp;&amp; fourthNum != fourthPlace){
          thirdPlace = fourthNum;
      }
      //thirdPlace end
  
      System.out.println("The sorted numbers are: "+ firstPlace + " " + secondPlace + " " + thirdPlace + " " + fourthPlace);
      }
  }
  </code></pre>
  
  <p>From this code, I keep getting the numbers in descending order, but there is one digit remaining, as indicated with a zero just so I know something did not go well.</p>
  
  <p><strong>Example I/O:</strong>
  When <em>40, 52, 6, and 7000</em> are inputted, 
  <em>7000, 0, 40, 6</em> are outputted, when the expected output is <em>7000, 52, 40, 6</em>.</p>
  
  <p>Not sure what I am doing wrong, but I would like to know so I can get a decent grade on this.</p>
  
  <p>Thank you.</p>