Download presentation
Presentation is loading. Please wait.
Published byBrook Powers Modified over 9 years ago
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!”); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.