Skip to content

Commit b294944

Browse files
committed
added new stub for Scanner recipe
1 parent 40272d4 commit b294944

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.teachingkidsprogramming.recipes.inDevelopment;
2+
3+
import java.util.Scanner;
4+
5+
public class FunWithScanner
6+
{
7+
private static Scanner scanner;
8+
private static Scanner scanner2;
9+
public static void main(String[] args)
10+
{
11+
scanner = new Scanner(System.in);
12+
scanner.useDelimiter("\\n");
13+
System.out.print("Enter an index: ");
14+
int index = scanner.nextInt();
15+
System.out.print("Enter a sentence: ");
16+
String sentence = scanner.next();
17+
System.out.println("\nYour sentence: " + sentence);
18+
System.out.println("Your index: " + index);
19+
}
20+
public static void makeAString()
21+
{
22+
String input = "1 fish 2 fish red fish blue fish";
23+
scanner2 = new Scanner(input);
24+
Scanner s = scanner2.useDelimiter("\\s*fish\\s*");
25+
System.out.println(s.nextInt());
26+
System.out.println(s.nextInt());
27+
System.out.println(s.next());
28+
System.out.println(s.next());
29+
s.close();
30+
}
31+
}

0 commit comments

Comments
 (0)