Class Notes (1,100,000)
US (480,000)
UW-Madison (5,000)
Lecture 27

COMP SCI 200 Lecture Notes - Lecture 27: ParsingPremium

Computer Sciences
Course Code
Paul Marker

This preview shows half of the first page. to view the full 3 pages of the document.
Comp Sci 200- Lecture 27- Exceptions pt 1
● Command-Line Arguments
○ Passing command-line arguments
■ Example: java CmdLineEx arg0 arg1 arg2
● This would give you three arguments
■ java CmdLineEx “arg0 arg1” arg2
● This would give you two arguments
● The two arguments in quotes become one argument
■ Command-Line arguments
● Arguments passed to the program when it’s launched
● In example: arg0, arg1, arg2
■ String[] args
● Passed to the main method via the String[] args
● In example: String[] args =  “arg0”, “arg1”, “arg2”
○ What is the output when executed with the command java CmdLineEx “Do or do
not, there is no try.”?
public class CmdLineEx {
public static void main(String[] args) {
int i = 0;
for (String s: args) {
i += s.length();
■ Answer: 23
○ Exercise instructions
You're Reading a Preview

Unlock to view full version

Subscribers Only