Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

In this page you can find the example usage for java.lang Math ceil.

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println(Math.ceil(10));
    System.out.println(Math.ceil(9.1));
    System.out.println(Math.ceil(5.5));
    System.out.println(Math.ceil(-10));
    System.out.println(Math.ceil(-4.4));
    System.out.println(Math.ceil(0));
}

From source file:MainClass.java

public static void main(String args[]) {
    System.out.println("The ceiling of 45.7 is " + Math.ceil(45.7));
}

From source file:Main.java

public static void main(String[] args) {

    double x = 125.9;
    double y = 0.12345;

    System.out.println("Math.ceil(" + x + ")=" + Math.ceil(x));
    System.out.println("Math.ceil(" + y + ")=" + Math.ceil(y));
    System.out.println("Math.ceil(-0.6)=" + Math.ceil(-0.6));

}

From source file:MainClass.java

public static void main(String args[]) {
    System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs(23.7));
    System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs(0.0));
    System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs(-23.7));
    System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil(9.2));
    System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil(-9.8));
    System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos(0.0));
    System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp(1.0));
    System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp(2.0));
    System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor(9.2));
    System.out.printf("Math.floor( -9.8 ) = %f\n", Math.floor(-9.8));
    System.out.printf("Math.log( Math.E ) = %f\n", Math.log(Math.E));
    System.out.printf("Math.log( Math.E * Math.E ) = %f\n", Math.log(Math.E * Math.E));
    System.out.printf("Math.max( 2.3, 12.7 ) = %f\n", Math.max(2.3, 12.7));
    System.out.printf("Math.max( -2.3, -12.7 ) = %f\n", Math.max(-2.3, -12.7));
    System.out.printf("Math.min( 2.3, 12.7 ) = %f\n", Math.min(2.3, 12.7));
    System.out.printf("Math.min( -2.3, -12.7 ) = %f\n", Math.min(-2.3, -12.7));
    System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n", Math.pow(2.0, 7.0));
    System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n", Math.pow(9.0, 0.5));
    System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin(0.0));
    System.out.printf("Math.sqrt( 900.0 ) = %f\n", Math.sqrt(900.0));
    System.out.printf("Math.sqrt( 9.0 ) = %f\n", Math.sqrt(9.0));
    System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan(0.0));
}

From source file:MainCLass.java

public static void main(String[] args) {
    double x = 2.4;
    double y = 9.5;
    double z = -1.3;

    System.out.println("round(x) = " + Math.round(x));
    System.out.println("round(y) = " + Math.round(y));
    System.out.println("round(z) = " + Math.round(z));
    System.out.println();// w w  w. java2  s .  c  o m
    System.out.println("ceil(x) = " + Math.ceil(x));
    System.out.println("ceil(y) = " + Math.ceil(y));
    System.out.println("ceil(z) = " + Math.ceil(z));
    System.out.println();
    System.out.println("floor(x) = " + Math.floor(x));
    System.out.println("floor(y) = " + Math.floor(y));
    System.out.println("floor(z) = " + Math.floor(z));
    System.out.println();
    System.out.println("rint(x) = " + Math.rint(x));
    System.out.println("rint(y) = " + Math.rint(y));
    System.out.println("rint(z) = " + Math.rint(z));
}

From source file:com.prl.sort.ShellSort.java

/**
 * @param args//from w  w w  .  jav  a2 s  . c  om
 */
public static void main(String[] args) {
    Integer a[] = { 1, 54, 6, 3, 78, 34, 12, 45, 56, 100 };
    int m = a.length;
    int temp = 0;
    while (true) {
        m = (int) Math.ceil(m / 2);
        for (int i = 0; i < m; i++) {
            for (int x = i + m; x < i; x += m) {
                int j = i - m;
                temp = a[i];
                for (; j >= 0 && temp < a[j]; j -= m) {
                    a[j + m] = a[i];
                }
                temp = a[j + m];
            }
        }

        if (m == 1) {
            break;
        }
    }
    System.out.println(StringUtils.join(a, ","));
}

From source file:Sieve.java

public static void main(String[] args) {
    // We will compute all primes less than the value specified on the
    // command line, or, if no argument, all primes less than 100.
    int max = 100; // Assign a default value
    try {//from  w  w  w. j ava 2s. co m
        max = Integer.parseInt(args[0]);
    } // Parse user-supplied arg
    catch (Exception e) {
    } // Silently ignore exceptions.

    // Create an array that specifies whether each number is prime or not.
    boolean[] isprime = new boolean[max + 1];

    // Assume that all numbers are primes, until proven otherwise.
    for (int i = 0; i <= max; i++)
        isprime[i] = true;

    // However, we know that 0 and 1 are not primes. Make a note of it.
    isprime[0] = isprime[1] = false;

    // To compute all primes less than max, we need to rule out
    // multiples of all integers less than the square root of max.
    int n = (int) Math.ceil(Math.sqrt(max)); // See java.lang.Math class

    // Now, for each integer i from 0 to n:
    //   If i is a prime, then none of its multiples are primes,
    //   so indicate this in the array. If i is not a prime, then
    //   its multiples have already been ruled out by one of the
    //   prime factors of i, so we can skip this case.
    for (int i = 0; i <= n; i++) {
        if (isprime[i]) // If i is a prime,
            for (int j = 2 * i; j <= max; j = j + i)
                // loop through multiples
                isprime[j] = false; // they are not prime.
    }

    // Now go look for the largest prime:
    int largest;
    for (largest = max; !isprime[largest]; largest--)
        ; // empty loop body

    // Output the result
    System.out.println("The largest prime less than or equal to " + max + " is " + largest);
}

From source file:mase.deprecated.SelectionBenchmark.java

public static void main(String[] args) {

    int L = 100, N = 10000;
    double[] truncationP = new double[] { 0.25, 0.50, 0.75 };
    int[] tournamentP = new int[] { 2, 5, 7, 10 };

    DescriptiveStatistics[] truncationStat = new DescriptiveStatistics[truncationP.length];
    for (int i = 0; i < truncationStat.length; i++) {
        truncationStat[i] = new DescriptiveStatistics();
    }/*from ww  w  .jav a2s. c  om*/
    DescriptiveStatistics[] tournamentStat = new DescriptiveStatistics[tournamentP.length];
    DescriptiveStatistics[] tournamentStat2 = new DescriptiveStatistics[tournamentP.length];
    for (int i = 0; i < tournamentStat.length; i++) {
        tournamentStat[i] = new DescriptiveStatistics();
        tournamentStat2[i] = new DescriptiveStatistics();
    }
    DescriptiveStatistics rouletteStat = new DescriptiveStatistics();
    DescriptiveStatistics rouletteStat2 = new DescriptiveStatistics();
    DescriptiveStatistics baseStat = new DescriptiveStatistics();

    for (int i = 0; i < N; i++) {
        // generate test vector
        double[] test = new double[L];
        for (int j = 0; j < L; j++) {
            test[j] = Math.random();
        }

        // truncation
        for (int p = 0; p < truncationP.length; p++) {
            double[] v = Arrays.copyOf(test, test.length);
            Arrays.sort(v);
            int nElites = (int) Math.ceil(truncationP[p] * test.length);
            double cutoff = v[test.length - nElites];
            double[] weights = new double[test.length];
            for (int k = 0; k < test.length; k++) {
                weights[k] = test[k] >= cutoff ? test[k] * (1 / truncationP[p]) : 0;
            }
            truncationStat[p].addValue(sum(weights));
        }

        // tournament
        for (int p = 0; p < tournamentP.length; p++) {
            double[] weights = new double[test.length];
            HashSet<Integer> added = new HashSet<Integer>();
            for (int k = 0; k < test.length; k++) {
                int idx = makeTournament(test, tournamentP[p]);
                weights[idx] += test[idx];
                added.add(idx);
            }
            tournamentStat2[p].addValue(added.size());
            tournamentStat[p].addValue(sum(weights));
        }

        // roulette
        double[] weights = new double[test.length];
        HashSet<Integer> added = new HashSet<Integer>();
        for (int k = 0; k < test.length; k++) {
            int idx = roulette(test);
            weights[idx] += test[idx];
            added.add(idx);
        }
        rouletteStat.addValue(sum(weights));
        rouletteStat2.addValue(added.size());

        // base
        baseStat.addValue(sum(test));
    }

    for (int p = 0; p < truncationP.length; p++) {
        System.out.println("Truncation\t" + truncationP[p] + "\t" + truncationStat[p].getMean() + "\t"
                + truncationStat[p].getStandardDeviation() + "\t" + ((int) Math.ceil(L * truncationP[p]))
                + "\t 0");
    }
    for (int p = 0; p < tournamentP.length; p++) {
        System.out.println("Tournament\t" + tournamentP[p] + "\t" + tournamentStat[p].getMean() + "\t"
                + tournamentStat[p].getStandardDeviation() + "\t" + tournamentStat2[p].getMean() + "\t"
                + tournamentStat2[p].getStandardDeviation());
    }
    System.out.println("Roulette\t\t" + rouletteStat.getMean() + "\t" + rouletteStat.getStandardDeviation()
            + "\t" + rouletteStat2.getMean() + "\t" + rouletteStat2.getStandardDeviation());
    System.out.println(
            "Base    \t\t" + baseStat.getMean() + "\t" + baseStat.getStandardDeviation() + "\t " + L + "\t0");
}

From source file:BasicMathDemo.java

public static void main(String[] args) {
    double aNumber = -191.635;

    System.out.println("The absolute value of " + aNumber + " is " + Math.abs(aNumber));
    System.out.println("The ceiling of " + aNumber + " is " + Math.ceil(aNumber));
    System.out.println("The floor of " + aNumber + " is " + Math.floor(aNumber));
    System.out.println("The rint of " + aNumber + " is " + Math.rint(aNumber));
}

From source file:com.super_bits.modulos.paginas.adminTools.PgAdminContainerObjetoTest.java

public static void main(String[] paramentros) {

    // Ask for user input
    System.out.print("Enter 1st value:");

    // use scanner to read the console input
    Scanner scan = new Scanner(System.in);
    String valor = scan.next();//ww  w  .  j  a  v a 2 s  . c o m
    double valorAtualizado = Double.parseDouble(valor) * 8.333;
    double calculoMultiplo = 10 * (Math.ceil(Math.abs(valorAtualizado / 10)));

    System.out.println(calculoMultiplo);

    double teste = (double) Math.round(Double.parseDouble(valor) * 8.3d) * 10 / 10d;
    System.out.println("TEste:" + teste);

    System.out.println("Result of the operation is " + valor);

    System.out.println(Precision.round(0.912385, 0, BigDecimal.ROUND_HALF_UP));
    int yourScale = 10;
    System.out.println(BigDecimal.valueOf(0.42344534534553453453 - 0.42324534524553453453).setScale(yourScale,
            BigDecimal.ROUND_HALF_UP));
}