Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.Scanner;
  3.  
  4. public class StatesAndCapitals {
  5.  
  6. public static void main(String[] args) throws Exception {
  7.  
  8. boolean[] x = new boolean[50];
  9. selectfive(x);
  10. File f = new File("capitals.txt");
  11. Scanner sc = new Scanner(f);
  12. System.out.println("What is the captial of");
  13. for (int i=0; i<50; i++){
  14. String inputLine = sc.nextLine();
  15. if (x[i] == true)
  16. System.out.println(inputLine);
  17. }//end while loop
  18. }//end main()
  19.  
  20. public static void selectfive(boolean[] arr){
  21. int x;
  22. for (int i=0; i<5; i++){
  23.  
  24. do{
  25. x = (int)(Math.random()*50);
  26. }while (arr[x] == true);
  27.  
  28. arr[x] = true;
  29. }
  30. }//end select five
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement