Numbers and Strings


Numbers and Strings Example

/**
 * Numbers and Strings Example #1
 *
 * @author Alyce Brady, Pamela Cutter
 */
public class NumbersAndStringsEx1
{
    /** The main function initiates execution of this program. */
    public static void main()
    {
        System.out.println ("Hello, world!");  // Print a String
        System.out.println (42);               // Print an int (integer)
        System.out.println (3.14159);          // Print a float or double
    }
}
Output:
    Hello, world!
    42
    3.14159 

/**
 * Numbers and Strings Example #2
 *
 * @author Alyce Brady, Pamela Cutter
 */
public class NumbersAndStringsEx2
{
    /** The main function initiates execution of this program. */
    public static void main()
    {
        System.out.println ("Hello, world!");  // Print a String
        System.out.println (42);               // Print an int (integer)
        System.out.println ("42");             // Print a String
        System.out.println (3.14159);          // Print a float or double
        System.out.println ("3.14159");        // Print a String
    }
}
Output:
    Hello, world!
    42
    42
    3.14159
    3.14159 

/**
 * Numbers and Strings Example #3
 *
 * @author Alyce Brady, Pamela Cutter
 */
public class NumbersAndStringsEx3
{
    /** The main function initiates execution of this program. */
    public static void main()
    {
        System.out.println ("2 + 3");
        System.out.println (2 + 3);
    }
}
Output:
    2 + 3
    5 

Alyce Brady, Kalamazoo College