ArrayTester4

ArrayTester4 - if...

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

View Full Document Right Arrow Icon
//Better yet with integers //Partially fill array - type Q to finish input / import java.util.Scanner; i public class ArrayTester4 { public static void main (String [] args) { int[] numArray = new int[10]; int count = 0; //count numbers entered String input; boolean done = false; Scanner in= new Scanner(System.in); while (!done) { System.out.print ("Enter number, Q to quit : " ); input = in.next(); // read number //test whether it's valid
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (input.equalsIgnoreCase("Q")) done = true; else { //convert input to an integer int inputNumber = Integer.parseInt(input); numArray[count] = inputNumber; // put the number in the array count++; // count it } } System.out.println ("There are " + count + " numbers in the array"); S for (int i = 0; i < count; 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