SHARE
TWEET

Untitled

joseleonweb Aug 23rd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top