CS 1410 Lecture 5: Scanners and Object Intro

53 views3 pages

Document Summary

Scanner; pre-written class, create a scanner object to use: new keyword creates objects. System. in corresponds to characters from the keyboard: scanner nameofscanner = new scanner(system. in), must import scanner class. Or type import java. util. scanner; between the package and class headers. String; class, object: string s, s = hello . Don"t need to use new keyword with strings, using is allowed, since. Strings are commonly made this is a feature of java: strings are objects like scanners. Methods need a specific object to work on: example; in. nextint(); doesn"t specify which scanner is used in. nextint(); in. next(); in. nextline(); To close a scanner object use in. close(): closes a file or keyboard use. //counts the number of characters in the string. Boolean comparestrings = s. equals(otherstring): compares if strings are equal. If using == sign, the comparison is if they are the same object. Using . equals(), the contents of the objects are compared.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents