Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array Access
- 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.
- For example, if the input is:
- 3
- 1
- 20
- The program should output
- Dover
- Boston
- and then exit.
- code:
- import java.util.Scanner;
- public class ArrayAccess{
- public static void main( String[] args ){
- String[] words = new String[]{"Durham", "Boston", "Portland", "Dover", "Portsmouth", "Exeter", "Kittery"};
- //YOUR CODE HERE
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement