jueves, 12 de diciembre de 2019

Algoritmo congruencial cuadratico en java (materia de simulación)


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Daniel
 */
public class CongruencialCuadratico {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner entrada = new Scanner(System.in);

        int x0, m = 0, a, b, c, g = 0, iteraciones, resultado;
        float r;

        System.out.println("itroduce el valor de x0: ");
        x0 = entrada.nextInt();
        System.out.println("itroduce el valor de a: ");
        a = entrada.nextInt();
        System.out.println("itroduce el valor de b: ");
        b = entrada.nextInt();
        System.out.println("itroduce el valor de c: ");
        c = entrada.nextInt();
        System.out.println("itroduce el valor de m: ");
        m = entrada.nextInt();
        System.out.println("itroduce el numero de iteraciones: ");
        iteraciones = entrada.nextInt();

        for (int i = 0; i < iteraciones; i++) {

            resultado = (int) (a * Math.pow(x0, 2) + (b * x0)) + (c);
//            m = (int) Math.pow(2, g);
            resultado = resultado % m;
            x0 = resultado;

            r = (float) resultado / (m - 1);
            x0 = resultado;
            System.out.println("x" + i + " = " + resultado + "   " + "r" + i + " = " + r);

        }

    }

}

No hay comentarios.:

Publicar un comentario