Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. Array Access
  2. The code given includes an array of town/city names (as strings) named words . The user will request these values by entering an index (int). Read integers from System.in and print the string at that index in the array until the user enters a number which is not a valid index into the array.
  3.  
  4. For example, if the input is:
  5.  
  6. 3
  7. 1
  8. 20
  9.  
  10. The program should output
  11.  
  12. Dover
  13. Boston
  14.  
  15. and then exit.
  16.  
  17.  
  18.  
  19. code:
  20.  
  21.  
  22.  
  23. import java.util.Scanner;
  24.  
  25. public class ArrayAccess{
  26. public static void main( String[] args ){
  27.  
  28. String[] words = new String[]{"Durham", "Boston", "Portland", "Dover", "Portsmouth", "Exeter", "Kittery"};
  29.  
  30. //YOUR CODE HERE
  31.  
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement