


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Exam; Class: LAB: Data Structures; Subject: Computer Science; University: Wellesley College; Term: Spring 2009;
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!
// Zero.java Java Foundations // //******************************************************************** Demonstrates an uncaught exception. public class Zero { //----------------------------------------------------------------- // Deliberately divides by zero to produce an exception. //----------------------------------------------------------------- public static void main (String[] args) { int numerator = 10; int denominator = 0; System.out.println ("Before the attempt to divide by zero."); System.out.println (numerator / denominator); System.out.println ("This text will not be printed."); } }
// here is code that // should generate no exceptions try { // code to monitor // several possible things // that can go wrong // goes here } catch (ExceptionTypeA ex) { //handler for ExceptionTypeA } catch (ExceptionTypeB ex) { //handler for ExceptionTypeB } // after a catch, code continues here
System.out.print ("Enter product code (STOP to quit): "); code = scan.nextLine(); while (!code.equals ("STOP")) { try { zone district = code.charAt(9); = Integer.parseInt(code.substring(3, 7)); valid++; if (zone == 'R' && district > 2000) banned++; } catch (StringIndexOutOfBoundsException exception) { System.out.println ("Improper code length: " + code); } catch (NumberFormatException exception) { System.out.println ("District is not numeric: " + code); } System.out.print ("Enter product code (STOP to quit): "); code = scan.nextLine(); }
1-
1-
/* Read in the contents of a web page line by line,
/* Read in lines of text from the keyboard,
/* Copies an input file to an output file.