Lesson Set 3 - CS 1136 LAB 3 Behavior of Scanner input with...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 1136 LAB 3 Behavior of Scanner input with Various Data Types and Unexpected Input One of the goals for this lab is to understand how the input buffer works with the Scanner input function. When using the input function by itself, a space will act like pressing the return key. It symbolizes an end of line to the Scanner . The “ String variable will accept any character the keyboard produces: letters, numbers, or symbols. The “int” type variables will accept only a leading sign (a blank, + or -) and numbers . Finally, “float” type variables will accept a leading sign, numbers and a period for the decimal. Input from the keyboard not used by a Scanner call will remain in the buffer. Exercise 1: Enter the following program into the compiler of your choice, save it on your hard drive and compile it. Refer to Labs 1 and 2 if you need assistance. (Note: If you copy the text from this lab into your compiler, the double quote characters need to be replaced in your code with double quotes recognized by the compiler). import java.util.Scanner; public class Lab3_Ex1 { public static void main (String [] args) { Scanner keyboard = new Scanner(System.in); float x; int y; char ch1, ch2; String name; String input; System.out.print( "Enter a character: "); input = keyboard.next();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/30/2012 for the course CS 1136 taught by Professor N/a during the Fall '08 term at University of Texas at Dallas, Richardson.

Page1 / 4

Lesson Set 3 - CS 1136 LAB 3 Behavior of Scanner input with...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online