UNA HERMOSA MOTO

UNA HERMOSA MOTO

miércoles, 10 de junio de 2015

PROBLEMA 43

43.- DADO UN RANGO DE NUMEROS ENTEROS, OBTENER LA CANTIDAD DE NUMEROS PARES QUE CONTIENE.



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package problema43dadounrangodenumerosenterosobtenerlacantidaddenumerospares;
import java.util.Scanner;
/**
 *

 */
public class PROBLEMA43DADOUNRANGODENUMEROSENTEROSOBTENERLACANTIDADDENUMEROSPARES {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
     int i, ni,nf,cp=0;
       Scanner teclado=new Scanner(System.in);
       System.out.println("Número Inicial: " );
       ni=teclado.nextInt();
       System.out.println("Número Final: " );
       nf=teclado.nextInt();
       i=ni+1;
       while (i<nf)
       {
       if  (i%2==0)
       {    
       cp+=1;
       }
       i++;
       
       }       
       System.out.println(" " );
       System.out.println("Cantidad Pares: "+cp);

    }
}

No hay comentarios:

Publicar un comentario