Guest User

ImSuperman

a guest
Jun 17th, 2015
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5. public class FindingAValueInAnArrayList2 {
  6.     public static void main(String[]args)
  7.     {
  8.         Scanner keyboard=new Scanner(System.in);
  9.         Random r=new Random();
  10.         ArrayList<Integer> arr=new ArrayList<Integer>();
  11.         int x=10;
  12.        
  13.         System.out.print("ArrayList :");
  14.         for(int i=0;arr.size()<10;i++)
  15.         {
  16.             arr.add(i,1+r.nextInt(1+100));
  17.            
  18.         }
  19.         System.out.println(arr);
  20.        
  21.         System.out.print("Value to find :");
  22.         int find=keyboard.nextInt();
  23.        
  24.         int curr=0;
  25.        
  26.         for(int j: arr)
  27.         {
  28.             if(j==find)
  29.             {  
  30.                 curr=j;
  31.                 System.out.println(find+" is in the ArrayList");
  32.             }
  33.         }
  34.  
  35.         if(curr!=find)
  36.         {
  37.             System.out.println(find+" is not in the ArrayList");
  38.         }
  39.        
  40.        
  41.        
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment