sábado, 26 de noviembre de 2022

ESTADISTICO

 Programa que da promedio, valor máximo,valor mínimo, varianza y desviación estandar en java codigo.


El programas siguiente utilizan esta clase Leer para que funcione, esta clase debe estar en la misma carpeta donde este cada programa. El programas a continuación deben tener esta clase.

Crear este archivo java con el siguiente código

import java.io.*;


public class Leer{

public static String dato() {

String sdato = "";

try

{

// Definir un flujo de caracteres de entrada: flujoE

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader flujoE = new BufferedReader(isr);

// Leer. La entrada finaliza al pulsar la tecla Entrar

sdato = flujoE.readLine();

}

catch(IOException e) {

System.err.println("Error: " + e.getMessage());

}

return sdato; // devolver el dato tecleado

}

public static short datoShort() {

try

{

return Short.parseShort(dato());

}

catch(NumberFormatException e) {

return Short.MIN_VALUE; // valor más pequeño

}

}

public static int datoInt() {

try {

return Integer.parseInt(dato());

}

catch(NumberFormatException e) {

return Integer.MIN_VALUE; // valor más pequeño

}

}

public static long datoLong() {

try

{

return Long.parseLong(dato());

}

catch(NumberFormatException e) {

return Long.MIN_VALUE; // valor más pequeño

}

}

public static float datoFloat()

{

try

{

return Float.parseFloat(dato());

}

catch(NumberFormatException e)

{

return Float.NaN; // No es un Número; valor float.

}

}

public static double datoDouble() {

try {

return Double.parseDouble(dato());

}

catch(NumberFormatException e) {

return Double.NaN; // No es un Número; valor double.

}

}

}

_______Crear archivo principal llamado Estadistica con el siguiente codigo

import java.lang.Math.*;

public class Estadistica {

public static void main(String[] args) {

int nElementos, b, guarda, suma,dos=2;

double prom, sumaV, vza, v; //, dos=2.0;

System.out.println("Programacion Orientada a Objetos ");

System.out.println("Programa de Calculos Estadisticos: ");

System.out.println("Nombre: jose ");

System.out.println();

System.out.print("¿Cuantos elementos son?: ");

nElementos = Leer.datoInt();

int[] m = new int[nElementos];

int i = 0;

suma=0;

System.out.println("Introduce los datos a calcular.");

for (i = 0; i < nElementos; i++) {

System.out.print("Elemento[" + i + "] = ");

m[i] = Leer.datoInt();

suma=suma+m[i]; }

do {

b=0;

for(i=0;i<nElementos-1;i++) {

if (m[i] > m[i+1]) {

guarda=m[i];

m[i]=m[i+1];

m[i+1]=guarda;

b=1; } }

}while (b==1);

System.out.println();

System.out.print("Dado los datos: ");

for (i = 0; i < nElementos; i++)

System.out.print(m[i] + " ");

System.out.println();

prom=suma/nElementos;

System.out.println("Su promedio es: " + prom);

System.out.println("El valor minimo es: " + m[0]);

System.out.println("El valor maximo es: " + m[nElementos-1]);

sumaV=0;

for (i = 0; i < nElementos; i++) {

v=(Math.pow((m[i] -prom), dos));

sumaV=sumaV+ v; }

vza=sumaV / nElementos - 1;

System.out.println("Su Varianza es: " + vza);

System.out.println("Su DesvStd es: " + Math.sqrt(vza));

System.out.println("\n\nFin del proceso."); }

} --------------------Configuration: <Default>----------------

Programacion Orientada a Objetos

Programa de Calculos Estadisticos:

Nombre: jose

¿Cuantos elementos son?: 5

Introduce los datos a calcular.

Dado los datos: 3 4 4 5 6

Elemento[0] = 3

Elemento[1] = 4

Elemento[2] = 6

Su promedio es: 4.0

Elemento[3] = 5

El valor minimo es: 3

Elemento[4] = 4

El valor maximo es: 6

Su Varianza es: 0.19999999999999996

Su DesvStd es: 0.44721359549995787

Fin del proceso.

Process completed.




:




martes, 22 de noviembre de 2022

Factorizar en java

 El programas siguiente utilizan esta clase Leer para que funcione, esta clase debe estar en la misma carpeta donde este cada programa. El programas a continuación deben tener esta clase.

Crear este archivo java con el siguiente código:


import java.io.*;


public class Leer{

public static String dato() {

String sdato = "";

try

{

// Definir un flujo de caracteres de entrada: flujoE

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader flujoE = new BufferedReader(isr);

// Leer. La entrada finaliza al pulsar la tecla Entrar

sdato = flujoE.readLine();

}

catch(IOException e) {

System.err.println("Error: " + e.getMessage());

}

return sdato; // devolver el dato tecleado

}

public static short datoShort() {

try

{

return Short.parseShort(dato());

}

catch(NumberFormatException e) {

return Short.MIN_VALUE; // valor más pequeño

}

}

public static int datoInt() {

try {

return Integer.parseInt(dato());

}

catch(NumberFormatException e) {

return Integer.MIN_VALUE; // valor más pequeño

}

}

public static long datoLong() {

try

{

return Long.parseLong(dato());

}

catch(NumberFormatException e) {

return Long.MIN_VALUE; // valor más pequeño

}

}

public static float datoFloat()

{

try

{

return Float.parseFloat(dato());

}

catch(NumberFormatException e)

{

return Float.NaN; // No es un Número; valor float.

}

}

public static double datoDouble() {

try {

return Double.parseDouble(dato());

}

catch(NumberFormatException e) {

return Double.NaN; // No es un Número; valor double.

}

}

}

________,Creat nuevo archivo Factoresprimos___


public class Factoresprimos {   

    public static void main(String[] args) {

                long numero,r,d,prueba;

      System.out.println("Numero a factorizar "); numero = Leer.datoLong();

    d = 2;

    do    {

                r = numero / d;

                if ((numero%d)==0)             {

                               System.out.print(d +" x ");

                               numero= r;         } 

                else         {

                               d=d +1;                  }

    }          while (r>1);           

                System.out.print(" 1 ");

    }

                }


--------------------Configuration: <Default>--------------------


Programa corrido

Numero a factorizar

150

2 x 3 x 5 x 5 x  1

Process completed.


jueves, 17 de noviembre de 2022

PREGUNTAS AL AZAR DE TABLAS DE MULTIPLICAR

 El programas siguiente utilizan esta clase Leer para que funcione, esta clase debe estar en la misma carpeta donde este cada programa. El programas a continuación deben tener esta clase.

Crear este archivo java con el siguiente código:

import java.io.*;


public class Leer{

  public static String dato() {

    String sdato = "";

    try

    {

      // Definir un flujo de caracteres de entrada: flujoE

      InputStreamReader isr = new InputStreamReader(System.in);

      BufferedReader flujoE = new BufferedReader(isr);

      // Leer. La entrada finaliza al pulsar la tecla Entrar

      sdato = flujoE.readLine();

    }

    catch(IOException e) {

      System.err.println("Error: " + e.getMessage());

    }

    return sdato; // devolver el dato tecleado

  }

  

  public static short datoShort() {

    try

    {

      return Short.parseShort(dato());

    }

    catch(NumberFormatException e) {

      return Short.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static int datoInt() {

    try {

      return Integer.parseInt(dato());

    }

    catch(NumberFormatException e) {

      return Integer.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static long datoLong() {

    try

    {

      return Long.parseLong(dato());

    }

    catch(NumberFormatException e) {

      return Long.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static float datoFloat()

  {

    try

    {

      return Float.parseFloat(dato());

    }

    catch(NumberFormatException e)

    {

      return Float.NaN; // No es un Número; valor float.

    }

  }

  

  public static double datoDouble() {

    try {

      return Double.parseDouble(dato());

    }

    catch(NumberFormatException e) {

      return Double.NaN; // No es un Número; valor double.

    }

  }

}

___________Crear nuevo archivo java con nombre preguntasalazardetablasdemultiplicar____________


import java.io.PrintStream;


public class preguntasalazardetablasdemultiplicar {


  public static void main(String[] args)

  {

                int r=0, resp=0, n1=0, n2=0, b=0, m=0;

   double cal;

    do

    { 

                n1=(int)(Math.random()*10)+1;

               

                n2=(int)(Math.random()*10)+1;

               

                System.out.printf("\n\n\t¿Cuanto es %2d por %2d?<0>Salir ",n1,n2);

                resp=Leer.datoInt();           

                 if (resp > 0 );

                 {

                                r=n1*n2;

                                if(r==resp)

                                {

                                               b=b+1;

        System.out.printf("\n\n\t CORRECTO!!Llevas %2d BUENAS Y %2d MALAS",b,m);

                                              

      }     

   else

                {

                               m=m+1;

                System.out.printf("\n\n\t INCORRECTO!!Llevas %2d BUENAS Y %2d MALAS",b,m);

                }                                                            

                }

    }while(resp!=0);

   

    cal=b*100/(b+m);

   

                System.out.printf("\n\n\t CALIFICACION = %.2f",cal);

  }

}


--------------------Configuration: <Default>--------------------

    ¿Cuanto es 10 por 9?<0>Salir 90



     CORRECTO!!Llevas 1 BUENAS Y 0 MALAS


    ¿Cuanto es 1 por 8?<0>Salir 0







viernes, 11 de noviembre de 2022

Sacar areas de triangulo, cuadrado y círculo en java con ciclos

 El programas siguiente utilizan esta clase Leer para que funcione, esta clase debe estar en la misma carpeta donde este cada programa. El programas a continuación deben tener esta clase.

Crear este archivo java con el siguiente código:

import java.io.*;


public class Leer{

  public static String dato() {

    String sdato = "";

    try

    {

      // Definir un flujo de caracteres de entrada: flujoE

      InputStreamReader isr = new InputStreamReader(System.in);

      BufferedReader flujoE = new BufferedReader(isr);

      // Leer. La entrada finaliza al pulsar la tecla Entrar

      sdato = flujoE.readLine();

    }

    catch(IOException e) {

      System.err.println("Error: " + e.getMessage());

    }

    return sdato; // devolver el dato tecleado

  }

  

  public static short datoShort() {

    try

    {

      return Short.parseShort(dato());

    }

    catch(NumberFormatException e) {

      return Short.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static int datoInt() {

    try {

      return Integer.parseInt(dato());

    }

    catch(NumberFormatException e) {

      return Integer.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static long datoLong() {

    try

    {

      return Long.parseLong(dato());

    }

    catch(NumberFormatException e) {

      return Long.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static float datoFloat()

  {

    try

    {

      return Float.parseFloat(dato());

    }

    catch(NumberFormatException e)

    {

      return Float.NaN; // No es un Número; valor float.

    }

  }

  

  public static double datoDouble() {

    try {

      return Double.parseDouble(dato());

    }

    catch(NumberFormatException e) {

      return Double.NaN; // No es un Número; valor double.

    }

  }

}

_________Creamos el segundo archivo java llamado Areas_______

import java.io.PrintStream;

public class Areas {

    public static void main(String[] args)

  {

    int opcion;

    double base, altura, radio, area;

    do

    {         

     System.out.printf("Calculo de areas de figuras geometricas");

     System.out.printf("\n\t 1)AREA DEL CIRCULO");

     System.out.printf("\n\t 2)AREA DEL RECTANGULO");  

     System.out.printf("\n\t 3)AREA DEL TRIANGULO"); 

     System.out.printf("\n\n\t ¿ESCOGE EL AREA A CALCULAR? <0>Salir ");         

     opcion = Leer.datoInt();               

     if (opcion > 0 && opcion<4) {

                if (opcion==1)

        {

            System.out.printf("\n\n\t ¿VALOR DEL RADIO? ");         

            radio = Leer.datoFloat();       

                area=radio*3.1416;

                System.out.printf("\n El Area es = %.2f ",area);

                System.out.printf("\n\n"); }

                if (opcion==2) {

            System.out.printf("\n\n\t ¿VALOR DE LA BASE? ");       

            base = Leer.datoFloat();        

                System.out.printf("\n\n\t ¿VALOR DE LA ALTURA? ");              

            altura = Leer.datoFloat();

                area=base * altura;

                System.out.printf("\n El Area es = %.2f ",area);

                System.out.printf("\n\n"); }

        if (opcion==3) {

            System.out.printf("\n\n\t ¿VALOR DE LA BASE? ");       

            base = Leer.datoFloat();        

                System.out.printf("\n\n\t ¿VALOR DE LA ALTURA? ");              

            altura = Leer.datoFloat();

                area=(base * altura)/2;

                System.out.printf("\n El Area es = %.2f ",area);

        System.out.printf("\nHecho por jose ");

                                               System.out.printf("\n\n"); }                        

      }     

    }while(opcion!=0); }      

      }

--------------------Configuration: <Default>--------------------

Calculo de areas de figuras geometricas

     1)AREA DEL CIRCULO

     2)AREA DEL RECTANGULO

     3)AREA DEL TRIANGULO

     ¿ESCOGE EL AREA A CALCULAR? <0>Salir 2

     ¿VALOR DE LA BASE? 1

¿VALOR DE LA ALTURA? 1

 El Area es = 1.00






miércoles, 9 de noviembre de 2022

Factorial en java

 Los programas siguientes utilizan esta clase Leer para que funcione, esta clase debe estar en la misma carpeta donde este cada programa. Todos los programas a continuación deben tener esta clase.

Crear este archivo java con el siguiente código:


import java.io.*;


public class Leer{

  public static String dato() {

    String sdato = "";

    try

    {

      // Definir un flujo de caracteres de entrada: flujoE

      InputStreamReader isr = new InputStreamReader(System.in);

      BufferedReader flujoE = new BufferedReader(isr);

      // Leer. La entrada finaliza al pulsar la tecla Entrar

      sdato = flujoE.readLine();

    }

    catch(IOException e) {

      System.err.println("Error: " + e.getMessage());

    }

    return sdato; // devolver el dato tecleado

  }

  

  public static short datoShort() {

    try

    {

      return Short.parseShort(dato());

    }

    catch(NumberFormatException e) {

      return Short.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static int datoInt() {

    try {

      return Integer.parseInt(dato());

    }

    catch(NumberFormatException e) {

      return Integer.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static long datoLong() {

    try

    {

      return Long.parseLong(dato());

    }

    catch(NumberFormatException e) {

      return Long.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static float datoFloat()

  {

    try

    {

      return Float.parseFloat(dato());

    }

    catch(NumberFormatException e)

    {

      return Float.NaN; // No es un Número; valor float.

    }

  }

  

  public static double datoDouble() {

    try {

      return Double.parseDouble(dato());

    }

    catch(NumberFormatException e) {

      return Double.NaN; // No es un Número; valor double.

    }

  }

}

_________________se crea otro archivo con la clase principal____

public class Factorial

{

  // Cálculo del factorial de un número

  long fact;

  public static long factorial(int n)

  {

    long fac;

    if (n == 0)

      return 1;

    else

      fac=1;

      do {

       fac=fac*n;

       n=n-1;

      }while (n>1);

      return fac;   

  }


  public static void main(String[] args)

  {

    int numero=0;

    long fact;

    do

    {

      System.out.print("¿Numero a calcular su factorial? ");

      numero = Leer.datoInt();

    }

    while (numero < 0 || numero > 25);

    fact = factorial(numero);

    System.out.println("\nPractica ");

    System.out.println("Calculo del factorial de un numero ");

    System.out.println("Realizado por: jose");

    System.out.println("\nEl factorial de " + numero + " es: " + fact);

  }

}


--------------------Configuration: <Default>--------------------

¿Numero a calcular su factorial? 8


Practica 

Calculo del factorial de un numero

Realizado por: jose


El factorial de 8 es: 40320

Process completed.





domingo, 6 de noviembre de 2022

CONVERTIR A DOLARES EN JAVA

 

Los programas siguientes utilizan esta clase Leer para que funcione, esta clase debe estar en la misma carpeta donde este cada programa. Todos los programas a continuación deben tener esta clase.

Crear este archivo java con el siguiente código:


import java.io.*;


public class Leer{

public static String dato() {

String sdato = "";

try

{

// Definir un flujo de caracteres de entrada: flujoE

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader flujoE = new BufferedReader(isr);

// Leer. La entrada finaliza al pulsar la tecla Entrar

sdato = flujoE.readLine();

}

catch(IOException e) {

System.err.println("Error: " + e.getMessage());

}

return sdato; // devolver el dato tecleado

}

public static short datoShort() {

try

{

return Short.parseShort(dato());

}

catch(NumberFormatException e) {

return Short.MIN_VALUE; // valor más pequeño

}

}

public static int datoInt() {

try {

return Integer.parseInt(dato());

}

catch(NumberFormatException e) {

return Integer.MIN_VALUE; // valor más pequeño

}

}

public static long datoLong() {

try

{

return Long.parseLong(dato());

}

catch(NumberFormatException e) {

return Long.MIN_VALUE; // valor más pequeño

}

}

public static float datoFloat()

{

try

{

return Float.parseFloat(dato());

}

catch(NumberFormatException e)

{

return Float.NaN; // No es un Número; valor float.

}

}

public static double datoDouble() {

try {

return Double.parseDouble(dato());

}

catch(NumberFormatException e) {

return Double.NaN; // No es un Número; valor double.

}

}

}

________El siguiente archivo es la clase principal __________

public class Cambiodemoneda{

                public static void main (String[]args){

                               int resp;

                               float cant;

                               double resultado;

                               System.out.println("CANTIDAD A CONVERTIR?");cant=Leer.datoFloat();

                               System.out.println("\n  1)CONVERTIR A PESOS");

                               System.out.println("  2)CONVERTIR A DOLARES");

                               System.out.println("  Escoje la opcion ");resp=Leer.datoInt();

                               if(resp==1)

                               {

                                               resultado=cant*20.00;

                               }

                               else

                               {

                                               resultado=cant/20.00;

                               }

                               System.out.println(".\n\nEL RESULTADO ES "+resultado);

                }

    }



--------------------Configuration: <Default>--------------------

CANTIDAD A CONVERTIR?

2


  1)CONVERTIR A PESOS

  2)CONVERTIR A DOLARES

  Escoje la opcion

1

.

EL RESULTADO ES 40.0

Process completed.

miércoles, 2 de noviembre de 2022

PRODUCTOS DE DOS NÚMEROS

 Los programas siguientes utilizan esta clase Leer para que funcione, esta clase debe estar en la misma carpeta donde este cada programa. Todos los programas a continuación deben tener esta clase.

Crear este archivo java con el siguiente código

import java.io.*;


public class Leer{

  public static String dato() {

    String sdato = "";

    try

    {

      // Definir un flujo de caracteres de entrada: flujoE

      InputStreamReader isr = new InputStreamReader(System.in);

      BufferedReader flujoE = new BufferedReader(isr);

      // Leer. La entrada finaliza al pulsar la tecla Entrar

      sdato = flujoE.readLine();

    }

    catch(IOException e) {

      System.err.println("Error: " + e.getMessage());

    }

    return sdato; // devolver el dato tecleado

  }

  

  public static short datoShort() {

    try

    {

      return Short.parseShort(dato());

    }

    catch(NumberFormatException e) {

      return Short.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static int datoInt() {

    try {

      return Integer.parseInt(dato());

    }

    catch(NumberFormatException e) {

      return Integer.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static long datoLong() {

    try

    {

      return Long.parseLong(dato());

    }

    catch(NumberFormatException e) {

      return Long.MIN_VALUE; // valor más pequeño

    }

  }

  

  public static float datoFloat()

  {

    try

    {

      return Float.parseFloat(dato());

    }

    catch(NumberFormatException e)

    {

      return Float.NaN; // No es un Número; valor float.

    }

  }

  

  public static double datoDouble() {

    try {

      return Double.parseDouble(dato());

    }

    catch(NumberFormatException e) {

      return Double.NaN; // No es un Número; valor double.

    }

  }

}

__________________

public class Producto {


    public static void main(String[] args) {

                int valor1=0;

                int valor2=0;

                int resultado=0;



                System.out.println("Dame el primer numero =>"); valor1 = Leer.datoInt();

                               System.out.println("Dame el segundo numero =>"); valor2 = Leer.datoInt();

                               resultado= valor1 * valor2;

                               System.out.println();

                               System.out.println("El resultado es =" + resultado);

    }

}


_____________________

Dame el primer numero =>

5

Dame el segundo numero =>

8


El resultado es =40

Process completed.




: