From CS160

Main: ScannerExample

// ******************************************************************
// ScannerExample.java
// Author: Asa Ben-Hur
// Examples of using expressions, variables and arithmetic operators
// ******************************************************************

import java.util.Scanner;

public class ScannerExample {
    public static void main(String[] args) {

        // instantiate an instance of Scanner which will read from System.in
        Scanner console = new Scanner(System.in);

        // prompt the user for input
        System.out.print("Please type three numbers: ");

        // use scanner to read three integers
        int num1 = console.nextInt();
        int num2 = console.nextInt();
        int num3 = console.nextInt();

        double average = (double) (num1 + num2 + num3) / 3;
        System.out.println("The average is " + average);
    }
}



Retrieved from http://www.cs.colostate.edu/~asa/courses/cs160/fall08/pmwiki/pmwiki.php/ScannerExample
Page last modified on September 28, 2008, at 03:30 PM MST