Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AreaCodes.java - This program prints a message for invalid area codes.
- // Input: Interactive.
- // Output: Error message or nothing.
- import javax.swing.*;
- public class AreaCodes
- {
- public static void main(String args[]) throws Exception
- {
- // Declare variables.
- int areaCode; // area code to look up in array.
- String areaString; // String version of area code.
- // Initialized array of area codes.
- int areaCodes[] = {269, 309, 425, 512, 608, 717, 870, 952, 815, 321};
- boolean foundIt = false; // Flag variable.
- int x; // Loop control variable.
- // Get user input.
- areaString = JOptionPane.showInputDialog("Enter area code: ");
- areaCode = Integer.parseInt(areaString);
- // Write your loop here.
- int x = 10;
- int count;
- final int areaCodes[];
- // Write your test statement here to see if there is
- // a match. Set the flag to true if area code is found.
- if(areaCodes[] = true) {
- System.out.println ("Your Area Code is found.");
- } else {
- System.out.println ("Area code not found");
- }
- // Test to see if area code was not found to determine if
- // "Area code not found" message should be printed.
- // if
- // (foundIt)
- // {
- // System.out.println ("Area code not found");
- // }
- System.exit(0);
- } // End of main() method.
- } // End of AreaCode class.
Add Comment
Please, Sign In to add comment