Enter first  integer:
12 -8
Enter second integer:
The sum of 12 plus -8 is 4

Answer:

The nextInt() method scans through the input stream character by character, grouping characters into groups that can be converted into numeric data. It ignores any spaces and end-of-lines that may separate these groups.

In the above, the user entered two groups on one line. Each call to nextInt() scanned in one group.

Integer Division Tester

Here is a new program made by modifying the first program.

import java.util.Scanner;
class IntDivideTest
{
  public static void main (String[] args) 
  { 
    Scanner scan = new Scanner( System.in );
 
    int dividend, divisor ;                      // int versions of input
    int quotient, remainder ;                    // results of "/" and "%"

    System.out.println("Enter the dividend:");   // read the dividend
    dividend = scan.nextInt();          

    System.out.println("Enter the divisor:");    // read the divisor
    divisor  = scan.nextInt();          

    quotient = dividend / divisor ;              // perform int math
    remainder= dividend % divisor ;

    System.out.println( dividend + " / " + divisor + " is " + quotient );
    System.out.println( dividend + " % " + divisor + " is " + remainder );
    System.out.println( quotient + " * " + divisor + 
        " + " + remainder + " is " + (quotient*divisor+remainder) );
  }
}

Run the program a few times. See what happens when negative integers are input.

QUESTION 16:

Do these notes still have your undivided attention?