Guest User

Untitled

a guest
Jul 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. // AreaCodes.java - This program prints a message for invalid area codes.
  2. // Input: Interactive.
  3. // Output: Error message or nothing.
  4.  
  5. import javax.swing.*;
  6.  
  7. public class AreaCodes
  8. {
  9. public static void main(String args[]) throws Exception
  10. {
  11. // Declare variables.
  12. int areaCode; // area code to look up in array.
  13. String areaString; // String version of area code.
  14. // Initialized array of area codes.
  15. int areaCodes[] = {269, 309, 425, 512, 608, 717, 870, 952, 815, 321};
  16. boolean foundIt = false; // Flag variable.
  17. int x; // Loop control variable.
  18.  
  19. // Get user input.
  20. areaString = JOptionPane.showInputDialog("Enter area code: ");
  21. areaCode = Integer.parseInt(areaString);
  22.  
  23. // Write your loop here.
  24. int x = 10;
  25. int count;
  26. final int areaCodes[];
  27.  
  28.  
  29. // Write your test statement here to see if there is
  30. // a match. Set the flag to true if area code is found.
  31. if(areaCodes[] = true) {
  32. System.out.println ("Your Area Code is found.");
  33. } else {
  34. System.out.println ("Area code not found");
  35. }
  36.  
  37.  
  38. // Test to see if area code was not found to determine if
  39. // "Area code not found" message should be printed.
  40. // if
  41. // (foundIt)
  42. // {
  43. // System.out.println ("Area code not found");
  44. // }
  45. System.exit(0);
  46. } // End of main() method.
  47. } // End of AreaCode class.
Add Comment
Please, Sign In to add comment