Advertisement
IanO-B

Untitled

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