Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SumarFinsLimit {
- public static void main (String[] args) {
- Scanner lector = new Scanner(System.in);
- System.out.print("Quin és el valor límit? ");
- int valor = lector.nextInt();
- lector.nextLine();
- int acumulat = 0;
- int comptador = 0;
- while(acumulat <= valor) {
- acumulat = acumulat + comptador;
- if(acumulat <= valor){
- System.out.println(comptador);
- comptador++;
- }
- }
- System.out.println("La suma dels valors positius és " + (acumulat - comptador) + ".");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement