Lab2 - try{ nonIntArray[j] = in.nextDouble(); j++; }

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

View Full Document Right Arrow Icon
import java.util.*; public class Lab2 { public static void main(String[] args){ int[] intArray = new int[10]; double[] nonIntArray = new double[10]; int i= 0; int j = 0; Scanner in = new Scanner(System.in); System.out.println("Enter a bunch of numbers:"); while(in.hasNext()){ try{ intArray[i] = in.nextInt(); i++; } catch(InputMismatchException e){
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: try{ nonIntArray[j] = in.nextDouble(); j++; } catch(InputMismatchException c){ while(in.hasNext()) {} } } } System.out.print("Integers: "); for(int k = 0;k<=i;k++){ System.out.print(intArray[k]+" "); } System.out.print("\nFloats: "); for(int l = 0; l<=j; l++){ System.out.print(nonIntArray[l]+" "); } } }...
View Full Document

This lab report was uploaded on 04/21/2008 for the course CSC 103 taught by Professor Franklin during the Spring '07 term at Cal Poly.

Ask a homework question - tutors are online