UNA HERMOSA MOTO

UNA HERMOSA MOTO

miércoles, 10 de junio de 2015

PROBLEMA 41


41.- OBTENER LA SUMA DE LOS PRIMEROS N NUMEROS NATURALES POSITIVOS




/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package problema41.suma.de.primeros.numeros.naturales.positivos;
import java.util.Scanner;
/**
 *

 */
public class PROBLEMA41SUMADEPRIMEROSNUMEROSNATURALESPOSITIVOS {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       int i, n, s=0;
      
       System.out.println("Número: " );
       Scanner teclado=new Scanner(System.in);
       n=teclado.nextInt();
       i=1;
       while (i<=n)
       {
       s=s+i;
       i=i+1;
       
       }       
       System.out.println(" " );
       System.out.println("Suma: "+s);

    }
}

No hay comentarios:

Publicar un comentario