File tree Expand file tree Collapse file tree
src/main/java/org/teachingkidsprogramming/recipes/inDevelopment Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ("\n Your 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+ }
You can’t perform that action at this time.
0 commit comments