ELIMINAR NUMERO

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Ejercicio3;

import Ejercicio1.Cola;
import java.util.Scanner;


/**
 *
 * @author l9531
 */
public class Numeros {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Cola<Integer> cola = new Cola();
        System.out.println("Ingrese cantidad de numeros");
        int can = sc.nextInt();
        for (int i = 0; i < can; i++) {
            System.out.println("Ingrese numero " + i);
            int n = sc.nextInt();
            cola.encolar(n);
        }
        System.out.println("Ingrese numero a abuscar");
        int numero = sc.nextInt();
        for (int i = 0; i <= can; i++) {
            int a = cola.desencolar();
            if (a==numero) {
                System.out.println("eliminado " + a);
            }else{
                cola.encolar(a);
            }

        }
        cola.mostrar();
     

    }
}

No hay comentarios.:

Publicar un comentario

Buscar este blog