Lab 13 code - Write a loop that will loop through and using...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 // Matt Hergenrether // Section 10 // Lab 13 // CS 1113 // Spring 2008 import java.util.* public class Lab13 { public static void main(String[] args) { // declare variables int num = 0 Scanner scan = new Scanner(System.in) // Use defensive programming to read in the first number // This number will be the number of ints to be read into the // array. if(scan.hasNextInt()) { num = scan.nextInt() } else { System.out.println("Error int value not found") System.exit(0) } // Declare an int array named iX and instatiate to be // of length of the number read in. // Ex. If the number read in was stored in variable num // int[] iX = new int[num] int[] ix = new int[num]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Write a loop that will loop through and using defensive // programming read in as many numbers that we said // we wanted entered above. // Hint: Since, we know how many items we are reading in // a for loop should be easy to implement. for(int iA = 0 iA < num iA++) { if(scan.hasNextInt()) { Sheet1 Page 2 ix[iA] = scan.nextInt() } else { System.out.println("Error int value not found") System.exit(0) } } // Write a second loop that will print out the contents // of the array. for(int iA = 0 iA < num iA++) { System.out.println(ix[iA]) } } // end of main method } // end of Lab13...
View Full Document

This note was uploaded on 09/28/2011 for the course CS 1113 taught by Professor Chandler during the Fall '08 term at Oklahoma State.

Page1 / 2

Lab 13 code - Write a loop that will loop through and using...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online