ArrayTester2

ArrayTester2 - numArray[count = inputNumber put the number...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// Partially fill array - type -1 to finish input  import java.util.Scanner;  public class ArrayTester2  public static void main (String [] args)      int[] numArray = new int[10];      int count = 0;   //count numbers entered         int inputNumber;      Scanner in = new Scanner(System.in);         System.out.print ("Enter number, -1 when done : " );         inputNumber = in.nextInt(); // read a number  while (inputNumber != -1) // test whether its valid                  {                                   System.out.print ("Enter number, -1 when done : " );            
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: numArray[count] = inputNumber; // put the number in the array count++; // count it inputNumber = in.nextInt(); // read next number } System.out.println ("There are " + count + " numbers in the array"); // How can we make this better??? for (int i = 0; i < numArray.length; i++) System.out.print(numArray[i] + " "); } }...
View Full Document

This note was uploaded on 06/07/2010 for the course CS 201 taught by Professor Staff during the Spring '08 term at Iona.

Ask a homework question - tutors are online