Advertisement
Cheshaia

TP3_Punto04_Java

Oct 17th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package Colas;
  2. import java.util.ArrayList;
  3. import java.util.LinkedList;
  4. import java.util.Queue;
  5. import java.util.Scanner;
  6.  
  7. public class Punto04 {
  8. public static void main(String[] args) {
  9. // TODO Auto-generated method stub
  10. int x,contcero=0,suma=0,fac=1;
  11. Queue<Integer> cola1=new LinkedList<Integer>();
  12. Queue<Integer> cola2=new LinkedList<Integer>();
  13. Queue<Integer> colafac=new LinkedList<Integer>();
  14. Scanner t= new Scanner(System.in);
  15. do{
  16. System.out.println("Ingrese un numero a la cola");
  17. x=t.nextInt();
  18. if(x!=99) {
  19. cola1.add(x);
  20. cola2.add(x);
  21. } }
  22. while (x!=99);
  23. System.out.println("desencolando");
  24. while(!cola1.isEmpty()) {
  25. int num= cola1.remove();
  26. System.out.println(num);
  27. if(num>0) {
  28. for (int i=1;i<=num;++i) {
  29. fac=fac*i;
  30. }
  31. colafac.add(fac);
  32. fac=1;
  33. } if (
  34. num<0) {
  35. suma=suma+num;
  36. } if(num==0) {
  37. contcero=contcero+1;
  38. }
  39. }
  40. System.out.println("la suma de los negativos es:"+suma);
  41. System.out.println("la cantidad de ceros ingresados es :"+contcero);
  42. while(!colafac.isEmpty()) {
  43. int y=cola2.remove();
  44. if(y>0) {
  45. System.out.print(" factorial: "+y+"="+colafac.remove());
  46.  
  47. }
  48.  
  49. }
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement