Wednesday, 3 December 2014

/ The "IfDemo1" class.  Page 102. (from the Carter book)

// Example 1: This program compares 2 integers supplied by the user
// and prints an appropriate message.

public class IfDemo1
{
    public static void main (String[] args)
    {
        System.out.println ("Please enter any integer");
        int first = In.getInt ();
        System.out.println ("Now, please provide a second integer");
        int second = In.getInt ();
        // compare the 2 integers to see if they're equal
        if (first == second)
        {
            System.out.println ("The 2 values input are equal");
        }
        else
        {
            System.out.println ("The 2 values input are not equal");
        }

    } // main method
} // IfDemo1 class

No comments:

Post a Comment