Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4.  
  5. public class Solution {
  6.  
  7.     public static void modul(ArrayList<Integer> wektor){
  8.         int suma=0;
  9.         for (Integer element:wektor) {
  10.             suma+=Math.abs(element);
  11.         }
  12.         System.out.println(suma);
  13.     }
  14.  
  15.     public static void pobierz(){
  16.         Scanner in=new Scanner(System.in);
  17.         ArrayList<Integer>wektor= new ArrayList<>();
  18.         boolean wyjscie=false;
  19.         String odpowiedz=" ";
  20.         while (wyjscie==false){
  21.             System.out.println("Podaj liczbe");
  22.             wektor.add(in.nextInt());
  23.             System.out.println("Podajesz dalej liczby? t/n  " );
  24.             odpowiedz=in.next();
  25.             if(odpowiedz.equals("n")){
  26.                 wyjscie=true;
  27.             }
  28.         }
  29.         modul(wektor);
  30.     }
  31.  
  32.     public static void main(String[] args) {
  33.         pobierz();
  34.         }
  35.  
  36.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement