Advertisement
joseleonweb

Untitled

Aug 23rd, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumarFinsLimit {
  4.   public static void main (String[] args) {
  5.     Scanner lector = new Scanner(System.in);
  6.  
  7.     System.out.print("Quin és el valor límit? ");
  8.     int valor = lector.nextInt();
  9.     lector.nextLine();
  10.  
  11.     int acumulat = 0;
  12.     int comptador = 0;
  13.  
  14.     while(acumulat <= valor) {
  15.       acumulat = acumulat + comptador;
  16.       if(acumulat <= valor){
  17.         System.out.println(comptador);
  18.         comptador++;
  19.       }
  20.     }
  21.     System.out.println("La suma dels valors positius és " + (acumulat - comptador) + ".");
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement