CSC-113-Tutorial 8 - Please try again. Enter the numerator:...

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

View Full Document Right Arrow Icon
KSU / CCIS / CS DEPARTMENT CSC-113, SPRING 2010 TUTORIAL 8 – EXCEPTIONS Exercise 1: Write a method and then write a main to test it. The method should handle some exceptions. - Start with a loop so that the user is repeatedly asked for the numerator and the denominator. For each set of data, the program prints out the result or an error message if there is a problem (division by zero or wrong input data.) - The program continues looping even if there is a problem. - Exit the loop when data entered for the numerator is "e" or "E". Don't print out an error message in this case and don't ask for the denominator. Here is sample output: Enter the numerator: 12 Enter the denominator: 4 12 / 4 is 3 Enter the numerator: 12 Enter the denominator : 0 You can't divide 12 by 0 Enter the numerator: N You entered bad data.
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: Please try again. Enter the numerator: E Good Bye Exercise 2: Write a method and then write a main to test it. The method handles the array exceptions. -The method asks the user to enter a size for an array of integers then asks him to fill the array with values. -Ask the user to enter the index for a value and print it on the screen. -The program should continue looping even if there is a problem. -Exit the loop when data entered for the index is a character and display the content of the array. Here is a sample output: Enter the array size: -3 Array size cannot be negative Enter the array size: 3 Enter a value: 1 Enter a value: 2 Enter a value: 3 Enter the index: 4 Bad index Enter the index: 2 The value in index 2 is 3 Enter the index: t The array content is 1 2 3 Good Bye...
View Full Document

Page1 / 2

CSC-113-Tutorial 8 - Please try again. Enter the numerator:...

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