Presentation is loading. Please wait.

Presentation is loading. Please wait.

String line = console.readLine() StringTokenizer st = new StringTokenizer(line)

Similar presentations


Presentation on theme: "String line = console.readLine() StringTokenizer st = new StringTokenizer(line)"— Presentation transcript:

1

2 String line = console.readLine()

3 StringTokenizer st = new StringTokenizer(line)

4 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens()

5 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true

6 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true String token = st.nextToken()

7 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true String token = st.nextToken() process the token somehow

8 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true String token = st.nextToken() process the token somehow false

9 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true String token = st.nextToken() process the token somehow false

10 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true String token = st.nextToken() process the token somehow false tokenizer is empty (but line is untouched)

11 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true String token = st.nextToken() process the token somehow false thus st = new StringTokenizer(line) allows us to reprocess the string (if we need to)

12 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true String token = st.nextToken() process the token somehow false thus st = new StringTokenizer(line) allows us to reprocess the string (if we need to)

13 String line = console.readLine() StringTokenizer st = new StringTokenizer(line) st.hasMoreTokens() true String token = st.nextToken() process the token somehow false thus st = new StringTokenizer(line) allows us to reprocess the string (if we need to) // sum is defined and initialized to zero outside try { int number = Integer.parseInt(token); sum = sum + number; } catch (Exception e) { System.out.println(token + “ not a number!”); }


Download ppt "String line = console.readLine() StringTokenizer st = new StringTokenizer(line)"

Similar presentations


Ads by Google