Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.*;
- import java.util.concurrent.ThreadLocalRandom;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Random rand = new Random();
- Scanner keyboard = new Scanner(System.in);
- int[] myList;
- myList = new int[10];
- int slot = 0;
- boolean foundInt = false;
- System.out.print("Array: ");
- for (int i = 0; i < myList.length; i++) {
- myList[i] = 1 + rand.nextInt(50);
- System.out.print(myList[i] + " ");
- }
- System.out.println();
- System.out.println("\nValue to find: ");
- int arrayChosen = keyboard.nextInt();
- for (int i = 0; i < myList.length; i++) {
- if (myList[i] == arrayChosen && !foundInt) {
- slot = i;
- foundInt = true;
- }
- } System.out.println();
- if (foundInt){
- System.out.println(arrayChosen + " is in slot " + slot);
- } else {
- System.out.println(arrayChosen + " is not in the array");
- }
- }
- }
Add Comment
Please, Sign In to add comment