title: How do I fix this code?
body: <pre><code>import java.util.Scanner;
  import java.util.Arrays;
  public class AttendanceManager {
  
  public static void main(String args[]) 
  {
      System.out.println("Enter the number of students that are to be recorded.");
      Scanner studentNum = new Scanner(System.in);
      int x = studentNum.nextInt();
      final int number[] = new int[x]; 
  
      for(int i=0; i&lt;x; i++)
      {
          System.out.println("Enter 1 if the student is present and 0 if the student is not.");
          final Scanner attendance = new Scanner(System.in);
          int inp = attendance.nextInt();
          int y = inp;
          switch (inp)
          {
          case 1:
              number[y] = 1;
              y = y++;
              break;
          case 0:
              number[y] = 2;
              y = y++;
              break;
          default:
              System.out.println("Please enter 1 or 0.");
              i--; 
          }
  
  
      }
      System.out.println("Total Students: " + number.length);
      for(int k=0; k&lt;number.length; k++)
      {
          if (number[k] == 1)
          System.out.println("Student " + (k+1) + " is " + "present.");
          else if (number[k] == 2)
          System.out.println("Student " + (k+1) + " is " + "absent.");
          else
          System.out.println("error");
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Output:</p>
  
  <pre class="lang-none prettyprint-override"><code>Enter the number of students that are to be recorded.
  5
  Enter 1 if the student is present and 0 if the student is not.
  1
  Enter 1 if the student is present and 0 if the student is not.
  0
  Enter 1 if the student is present and 0 if the student is not.
  1
  Enter 1 if the student is present and 0 if the student is not.
  1
  Enter 1 if the student is present and 0 if the student is not.
  0
  Total Students: 5
  Student 1 is absent.
  Student 2 is present.
  error
  error
  error
  </code></pre>
  
  <p>why do the last 3 not get assigned to 1 or 0?</p>