UNA HERMOSA MOTO

UNA HERMOSA MOTO

miércoles, 10 de junio de 2015

PROBLEMA 45

45.- DADO UN NÚMERO DETERMINAR CUÁNTOS DÍGITOS TIENE.



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

 */
public class Problema45dadounnumerodeterminarcuantosdigitostiene {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       int n,c=0;
       Scanner teclado=new Scanner(System.in);
       System.out.println("Número: " );
       n=teclado.nextInt();
       
       while (n>0)
       {
       n=n/10;
       c+=1;
       }
       System.out.println(" " );
       System.out.println("Cantidad de Dígitos: "+c);

    }
}

PROBLEMA 44

44.- OBTENER LA CANTIDAD DE LOS PRIMEROS N NUMEROS MULTIPLOS DE 5.



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

 */
public class Problema44cantidaddeprimerosnnumerosmultiplosde5 {

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

    }
}

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);

    }
}

PROBLEMA 42

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



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

 */
public class PROBLEMA42DADOUNRANGODENUMEROSENTEROSOBTENERLACANTIDADDENUMEROSENTEROSQUECONTIENE {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     int i, ni,nf,c=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)
       {
       c+=1;
       i++;
       
       }       
       System.out.println(" " );
       System.out.println("Cantidad: "+c);

    }
}

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);

    }
}