// Simple math program in Java

import java.util.Random;

public class SimpleMath {

    public static void main(String[] args) {

        // Variable definitions
        int var0 = 2;
        int var1 = 5;
        int var2 = 3;

        // Math operators
        System.out.println("2 + 5 = " + (var0 + var1));
        System.out.println("5 - 2 = " + (var1 - var0));
        System.out.println("2 * 5 = " + (var0 * var1));
        System.out.println("5 / 2 = " + (var1 / var0));
        System.out.println("5 * 2 - 3 = " + (var1 * var0 - var2));
        System.out.println(Math.abs(-10));
        
        // Random number
        Random random = new Random();
        System.out.println(random.nextFloat());
    }
}

© 2012 CS160 Colorado State University. All Rights Reserved.