Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Solution {
- public static void modul(ArrayList<Integer> wektor){
- int suma=0;
- for (Integer element:wektor) {
- suma+=Math.abs(element);
- }
- System.out.println(suma);
- }
- public static void pobierz(){
- Scanner in=new Scanner(System.in);
- ArrayList<Integer>wektor= new ArrayList<>();
- boolean wyjscie=false;
- String odpowiedz=" ";
- while (wyjscie==false){
- System.out.println("Podaj liczbe");
- wektor.add(in.nextInt());
- System.out.println("Podajesz dalej liczby? t/n " );
- odpowiedz=in.next();
- if(odpowiedz.equals("n")){
- wyjscie=true;
- }
- }
- modul(wektor);
- }
- public static void main(String[] args) {
- pobierz();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement