Advertisement
N3ggg

Untitled

Feb 26th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.util.*;
  2. public class Main {
  3.  
  4. public static void main(String[] args) {
  5. Scanner keyboard = new Scanner(System.in);
  6. Random r = new Random();
  7. int a[] = new int[10];
  8. int times=0;
  9. System.out.print("Array: ");
  10. for(int i=0; i<a.length; i++){
  11. a[i]=1+r.nextInt(50);
  12. System.out.print(a[i]+" ");
  13. }
  14. System.out.println();
  15. System.out.print("Value to find: ");
  16. int value = keyboard.nextInt();
  17. System.out.println();
  18. for(int j=0; j<a.length; j++){
  19. if (value==a[j]){
  20. times++;
  21. }
  22. }
  23. System.out.println(value+" was found "+ times +" times.");
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement