Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>nextInt()</code> was causing the immediate <code>nextLine()</code> so avoided using it. This will work for 2 or more words as well...</p> <pre><code>System.out.println("Enter the number of pets to store information for:"); int amount = Integer.parseInt(keyboard.nextLine()); String [] petNames = new String [amount]; String [] petTypes = new String [amount]; int [] numVisits = new int [amount]; outputStream.println("Patient Data:"); outputStream.println("Pet Name Pet Type Number of Visits"); for (int index=0;index &lt; amount; index++) { System.out.println("Type the pet name, then press Enter:"); petNames[index] = keyboard.nextLine(); System.out.println("Type the animal type (dog, cat, bird, rodent), then press Enter:"); petTypes[index] = keyboard.nextLine(); System.out.println("Type the number of visits last year, then press Enter:"); numVisits[index] = Integer.parseInt(keyboard.nextLine()); outputStream.printf("%8s %-8s %-8d%n", petNames[index], petTypes[index], numVisits[index]); } </code></pre> <p>As mentioned earlier, you don't have to use arrays here. You can do this instead...</p> <pre><code>System.out.println("Enter the number of pets to store information for:"); int amount = Integer.parseInt(keyboard.nextLine()); outputStream.println("Patient Data:"); outputStream.println("Pet Name Pet Type Number of Visits"); String petName = new String(); String petType = new String(); int numVisit = 0; for (int index = 0; index &lt; amount; index++) { System.out.println("Type the pet name, then press Enter:"); petName = keyboard.nextLine(); System.out.println("Type the animal type (dog, cat, bird, rodent), then press Enter:"); petType = keyboard.nextLine(); System.out.println("Type the number of visits last year, then press Enter:"); numVisit = Integer.parseInt(keyboard.nextLine()); outputStream.printf("%8s %-8s %-8d%n", petName, petType, numVisit); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload