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