Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- int[] a;
- a = new int[10];
- Random r = new Random();
- Scanner s = new Scanner(System.in);
- for (int i = 0; i < a.length; i++) {
- a[i] = 1 + r.nextInt(50);
- System.out.println(a[i]);
- }
- System.out.println("Value to find:");
- int v = s.nextInt();
- int found = 0;
- for (int i = 0; i < a.length; i++) {
- if (v == a[i]) {
- System.out.println(v + " is in slot " + i);
- found++;
- }
- }
- if (found==0){
- System.out.println(v+" is not in the array.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement