Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class SecuencialSearch {
- public static void main(String[] args) {
- SecuencialSearch pq = new SecuencialSearch();
- Scanner x = new Scanner(System.in);
- ArrayList<Integer> elements = new ArrayList<Integer>();
- int nc = 0;
- while (nc < 100) {
- elements.add((int) (Math.random() * 200) + 1);
- System.out.print(elements.get(nc) + " ");
- nc++;
- }
- nc = 0;
- System.out.println("");
- int sec = x.nextInt();
- boolean founded = false;
- while (nc < 100) {
- if (sec == elements.get(nc)) {
- founded = true;
- break;
- }
- nc++;
- }
- if (founded) {
- System.out.println("Se encontro en " + (nc+1) + " comparaciones "
- + "\n en la posicion " + nc);
- }else{
- System.out.println("Jajajaja :v");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement