Robert_Manea

suma vector java

Mar 3rd, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. package pkg40313;
  8. import java.util.*;
  9. /**
  10. *
  11. * @author L1PC08
  12. */
  13. public class Main {
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. public static void main(String[] args) {
  19. int x[],i,n,s=0;
  20.  
  21. Scanner ts=new Scanner(System.in);
  22. System.out.println(" Introdu n ");
  23. n=ts.nextInt();
  24. x=new int[n];
  25. System.out.println("Introdu vectorul");
  26. for(i=0;i<n;i++){
  27. System.out.println("x["+i+"]=");
  28. x[i]=ts.nextInt();}
  29. for(i=0;i<n;i++)
  30. if(x[i]<5)
  31. s=s+x[i];
  32. System.out.println(" Suma este"+s);
  33.  
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment