Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Colas;
- import java.util.ArrayList;
- import java.util.LinkedList;
- import java.util.Queue;
- import java.util.Scanner;
- public class Punto04 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int x,contcero=0,suma=0,fac=1;
- Queue<Integer> cola1=new LinkedList<Integer>();
- Queue<Integer> cola2=new LinkedList<Integer>();
- Queue<Integer> colafac=new LinkedList<Integer>();
- Scanner t= new Scanner(System.in);
- do{
- System.out.println("Ingrese un numero a la cola");
- x=t.nextInt();
- if(x!=99) {
- cola1.add(x);
- cola2.add(x);
- } }
- while (x!=99);
- System.out.println("desencolando");
- while(!cola1.isEmpty()) {
- int num= cola1.remove();
- System.out.println(num);
- if(num>0) {
- for (int i=1;i<=num;++i) {
- fac=fac*i;
- }
- colafac.add(fac);
- fac=1;
- } if (
- num<0) {
- suma=suma+num;
- } if(num==0) {
- contcero=contcero+1;
- }
- }
- System.out.println("la suma de los negativos es:"+suma);
- System.out.println("la cantidad de ceros ingresados es :"+contcero);
- while(!colafac.isEmpty()) {
- int y=cola2.remove();
- if(y>0) {
- System.out.print(" factorial: "+y+"="+colafac.remove());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement