CS2133 hw 1 #1

CS2133 hw 1 #1 - System.exit(0); } for(int i = 0; i...

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

View Full Document Right Arrow Icon
// Matt Hergenrether // CS 2133 // February 11, 2009 // Homework 1 #1 // Arrays and scanning in values import java.util.*; // util contains the Scanner class public class test { public static void main(String[] args) { Scanner scan = new Scanner(System.in); // Declare variables int n = 0; int[] nums; //declares an array boolean keepgoing; boolean valid; String data = " "; nums = new int[51]; // allocates memory for 51 integers keepgoing = true; valid = true; while(keepgoing) { valid = true; System.out.println("Enter a value in the interval [0, 50]."); if(scan.hasNextInt()) { n = scan.nextInt(); } else { System.out.println("Error: not a valid entry");
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
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.exit(0); } for(int i = 0; i <= 50; i++) { if( n == i) { nums[i]++; } } while(valid) { valid = false; System.out.println("Would you like to enter another value (y or n). "); data = scan.next(); if (data.equalsIgnoreCase("y")) { keepgoing = true; } else if (data.equalsIgnoreCase("n")) { keepgoing = false; } else { System.out.println("Error: not a valid entry"); valid = true; } } } for(int x = 0; x<=50; x++) { if(nums[x] != 0) { System.out.println("The value " + x + " was read in " + nums[x] + " times." ); } } } }...
View Full Document

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

Page1 / 3

CS2133 hw 1 #1 - System.exit(0); } for(int i = 0; i...

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

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