Skip to content

Commit 7d01650

Browse files
committed
therapeutic refactoring on Scanner w/@samanthalangit
1 parent db9205f commit 7d01650

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/main/java/org/teachingkidsprogramming/recipes/inDevelopment/FunWithScanner.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.Iterator;
44
import java.util.Scanner;
5+
//
6+
//**this recipe is being designed to show how to use the Java Scanner Object***********//
7+
//
58

69
public class FunWithScanner
710
{
@@ -10,27 +13,27 @@ public static void main(String[] args)
1013
{
1114
makeAString();
1215
}
16+
//
1317
public static void makeAString()
1418
{
15-
String input = "1 fish 2 fish red fish blue fish, ";
19+
final String input = "1 fish 2 fish red fish blue fish,black fish,blue fish,old fish,new fish ";
1620
scanner = new Scanner(input);
17-
System.err.println("\nIt is said that there are: " + input);
21+
System.err.println("\nWe have: " + input + '\n');
1822
Scanner s = scanner.useDelimiter("\\s*fish\\s*");
1923
System.out.println("So: " + s.nextInt() + " and " + s.nextInt());
2024
System.out.println("And: " + s.next() + " and " + s.next() + '\n');
21-
for (String unit : new Iterable<String>()
25+
for (String fish : new Iterable<String>()
2226
{
23-
private String units = "black fish,blue fish,old fish,new fish";
2427
@Override
2528
public Iterator<String> iterator()
2629
{
27-
Scanner scanner = new Scanner(units);
30+
scanner = new Scanner(input);
2831
scanner.useDelimiter(",");
2932
return scanner;
3033
}
3134
})
3235
{
33-
System.out.println("And also: " + unit);
36+
System.out.println("And then: " + fish);
3437
}
3538
s.close();
3639
}

0 commit comments

Comments
 (0)