C OMP 401 B ASICS O F S CANNING Instructor: Prasun Dewan (FB 150, [email protected])
-
Upload
elizabeth-pitts -
Category
Documents
-
view
213 -
download
0
Transcript of C OMP 401 B ASICS O F S CANNING Instructor: Prasun Dewan (FB 150, [email protected])
Slide 1
Comp 401 Basics Of ScanningInstructor: Prasun Dewan (FB 150, [email protected])
#Scanning Problem Scanning image for text.Scanning frequencies for radio stations.Finding words in a sentenceFinding identifiers, operators, in a program
#Scanning Problem
Program name(First) Argument or option to the programoutput#3ScanningJohnF.KenndyetokentokenInputstreamTokenStreamtokentokentoken
#4AlgorithmJohnF.Kenndyemarker0Output: J
#5AlgorithmJohnF.Kenndyemarker1Output: JString inputLine
#6AlgorithmJohnF.Kenndyemarker2Output: J
#7AlgorithmJohnF.Kenndyemarker5Output: JF
#8AlgorithmJohnF.Kenndyemarker6Output: JF
#9AlgorithmJohnF.Kenndyemarker8Output: JFK
#10AlgorithmJohnF.Kenndyemarker9Output: JFK
#11AlgorithmJohnF.Kenndyemarker14Output: JFK
#12Solution (edit in class)package warmup;public class AnUpperCasePrinter { public static void main(String[] args){ } }
#13Solutionpublic class AnUpperCasePrinter { public static void main(String[] args){if (args.length != 1) {System.out.println("Illegal number of arguments:" + args.length + ". Terminating program.");System.exit(-1);}System.out.println("Upper Case Letters:");int index = 0;while (index < args[0].length()) {if (Character.isUpperCase(args[0].charAt(index))) System.out.print(args[0].charAt(index));index++;}System.out.println(); }
Print on new vs previous line
#14Detecting Upper Case public class AnUpperCasePrinter { public static void main(String[] args){if (args.length != 1) {System.out.println("Illegal number of arguments:" + args.length + ". Terminating program.");System.exit(-1);}System.out.println("Upper Case Letters:");int index = 0;while (index < args[0].length()) {char nextLetter = args[0].charAt(index) ;if (nextLetter >= A && nextLetter