Advertisement
joseleonweb

Untitled

Aug 30th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumaEntersComes {
  4.   public static void main (String[] args) {
  5.     Scanner lector = new Scanner(System.in);
  6.  
  7.     System.out.println("Escriu un text compost per nombres separats per comes:");
  8.     String text = lector.nextLine();
  9.  
  10.     String[] arrayValors = text.split(",");
  11.     int suma = 0;
  12.     for(int i = 0; i < arrayValors.length; i++) {
  13.       int valor = Integer.parseInt(arrayValors[i]);
  14.       suma = suma + valor;
  15.     }
  16.     System.out.println("La suma és " + suma + ".");
  17.   }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement