Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.Scanner;
- public class StatesAndCapitals {
- public static void main(String[] args) throws Exception {
- boolean[] x = new boolean[50];
- selectfive(x);
- File f = new File("capitals.txt");
- Scanner sc = new Scanner(f);
- System.out.println("What is the captial of");
- for (int i=0; i<50; i++){
- String inputLine = sc.nextLine();
- if (x[i] == true)
- System.out.println(inputLine);
- }//end while loop
- }//end main()
- public static void selectfive(boolean[] arr){
- int x;
- for (int i=0; i<5; i++){
- do{
- x = (int)(Math.random()*50);
- }while (arr[x] == true);
- arr[x] = true;
- }
- }//end select five
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement