Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,570 --> 00:00:03,570
Scanner uses the delimiter pattern to read your data.
2
00:00:06,410 --> 00:00:10,130
Before we continue with our dealership, you should understand how delimiters work.
3
00:00:11,750 --> 00:00:16,160
The first thing I'll need you to do is create a new class by yourself inside Section three folder,
4
00:00:16,460 --> 00:00:21,890
create a new file name, delimiters Java and make sure the delimiters class has a main method.
5
00:00:28,760 --> 00:00:34,950
The delimiter separates your user input and the delimiter for user input is whitespace by default.
6
00:00:35,690 --> 00:00:41,840
So if you input three numbers separated by a white space, it takes three scanned next in methods to
7
00:00:41,840 --> 00:00:42,520
pick them up.
8
00:00:43,570 --> 00:00:48,370
Each method skips the delimiter, it skips the white space, and it picks up the next integer.
9
00:00:53,190 --> 00:00:59,070
It doesn't matter how much white space there is between each input scandal and skips the delimiter and
10
00:00:59,070 --> 00:01:01,170
it reads the next integer that you input.
11
00:01:04,420 --> 00:01:10,960
Even if you press enter many times between each input next and skips all the white space and it reads
12
00:01:10,960 --> 00:01:17,500
the next input and because next and skips the delimiter, we say that it follows the delimiter pattern.
13
00:01:19,840 --> 00:01:25,990
Next internship's the delimiter and reads the next integer value, next long skips the delimiter and
14
00:01:25,990 --> 00:01:27,490
reads the next long value.
15
00:01:27,850 --> 00:01:31,810
Next double also skips to the limiter and reads the next double value.
16
00:01:32,230 --> 00:01:36,580
Next skips the delimiter and reads the next string value.
17
00:01:38,020 --> 00:01:40,520
Hope you're ready, because we're about to write a lot of code.
18
00:01:42,090 --> 00:01:43,680
First time and ask the user to.
19
00:01:47,000 --> 00:01:52,880
NASA managers and for the sake of example, am going to ask them to write each value on the same line.
20
00:01:58,060 --> 00:01:59,380
Then I'm going to copy this.
21
00:02:03,550 --> 00:02:06,250
And ask them to enter two very big integers.
22
00:02:10,070 --> 00:02:11,240
To decimals.
23
00:02:15,260 --> 00:02:17,150
And to tax the values.
24
00:02:20,570 --> 00:02:25,910
Now we're going to pick up every value using the appropriate scanner method, so first I'm going to
25
00:02:25,910 --> 00:02:30,290
set up a new scanner right scanner, wait for the auto import.
26
00:02:34,810 --> 00:02:41,230
Skin is equal to a new skin, for instance, that can receive input from the system system in.
27
00:02:45,430 --> 00:02:51,880
First, we're going to need to scan next and methods, and no one is equal to the next integer.
28
00:02:56,900 --> 00:03:00,350
And number two is equal to the integer that follows.
29
00:03:07,390 --> 00:03:10,240
Then we're going to need to scan the next long values.
30
00:03:12,820 --> 00:03:16,300
Big no one is equal to the next long value.
31
00:03:22,840 --> 00:03:26,680
Big number two is equal to the scandal next long value.
32
00:03:28,900 --> 00:03:35,980
Now for decimals, we use next double double decimal one is equal to Scandi, next double.
33
00:03:39,570 --> 00:03:43,920
And double decimal two is equal to scandal next double.
34
00:03:52,720 --> 00:03:58,390
And finally, to pick up text we're not going to use next line, we're going to use Scandal next because
35
00:03:58,390 --> 00:04:03,040
unlike next line, each scan, the next method is going to follow the delimiter pattern.
36
00:04:04,360 --> 00:04:08,650
Such that it's going to set the delimiter, the white space that you put in between each value, it's
37
00:04:08,650 --> 00:04:12,430
going to skip that and pick up only the next value that it sees.
38
00:04:14,960 --> 00:04:18,740
All right, as always, we're going to close scanner scanned close.
39
00:04:19,730 --> 00:04:21,810
And that was a lot of code, we're almost done.
40
00:04:22,580 --> 00:04:25,700
The last thing we're going to do is print the values that scanner picks up.
41
00:04:27,410 --> 00:04:33,310
So we'll print remember, we can use the escape character to create a type of space and we'll say the
42
00:04:33,320 --> 00:04:35,540
managers are Kolan.
43
00:04:37,560 --> 00:04:43,290
No one break the string at some space between printing number one and number two.
44
00:04:44,900 --> 00:04:46,640
Now, I'm going to copy this four times.
45
00:04:50,820 --> 00:04:55,500
And here will say big integers and we'll print both numbers that we pick up.
46
00:04:59,850 --> 00:05:01,350
There will say decimals.
47
00:05:04,940 --> 00:05:07,310
And we'll print both decimals that we pick up.
48
00:05:17,090 --> 00:05:20,360
And here will say words and will print both words.
49
00:05:26,450 --> 00:05:28,940
That was a lot of code, and I'm happy to say that we're done.
50
00:05:29,380 --> 00:05:31,150
Let's run it and see what happens.
51
00:05:42,080 --> 00:05:43,640
Here, I'm going to put two integers.
52
00:05:44,580 --> 00:05:46,080
Two very big injuries.
53
00:05:49,450 --> 00:05:50,680
You decimals.
54
00:05:53,460 --> 00:05:54,870
And two words.
55
00:05:58,980 --> 00:06:02,610
And everything worked out, we successfully picked up every value and printed it.
56
00:06:04,410 --> 00:06:09,660
Each scanner method skips the delimiter, it skips the whitespace, and it picks up only the next value
57
00:06:09,660 --> 00:06:10,500
that it sees.
58
00:06:10,980 --> 00:06:15,840
It doesn't matter how much white space there is between each value, there could be 20 lines worth of
59
00:06:15,840 --> 00:06:16,490
white space.
60
00:06:16,770 --> 00:06:20,700
It skips all of it and it only picks up the next value that it sees.
61
00:06:23,380 --> 00:06:29,500
What about skin next line, scandal, next line reads the entire line, it doesn't care about delimiters,
62
00:06:29,500 --> 00:06:33,270
it reads the entire line, including all of the white space in between each value.
63
00:06:34,060 --> 00:06:37,510
If you scan the next line, it's going to read this whole line is one input.
64
00:06:41,890 --> 00:06:43,090
We're going to try this in our code.
65
00:06:43,450 --> 00:06:46,250
I'm going to replace each method with scanned next line.
66
00:06:46,750 --> 00:06:52,480
I'm going to say string numbers is equal to everything that appears in the next line.
67
00:06:52,840 --> 00:06:55,930
It's going to read every value in that line and return it as a string.
68
00:06:58,920 --> 00:07:04,050
Then we'll say string big numbers is also equal to all the values that appear in the next line.
69
00:07:10,360 --> 00:07:12,460
And we'll do the same thing for decimals.
70
00:07:17,150 --> 00:07:21,920
And string text is also going to be equal to all the values that appear in the next line.
71
00:07:45,900 --> 00:07:47,280
I'm going to rerun the code.
72
00:07:54,150 --> 00:07:55,380
Put in some values.
73
00:08:10,370 --> 00:08:13,970
This is what separates Scandi next line from every other Skinner method.
74
00:08:14,240 --> 00:08:16,100
It reads everything line by line.
75
00:08:28,090 --> 00:08:34,049
So all of this boils down to one question why exactly do we get this scandal next line trap?
76
00:08:34,059 --> 00:08:34,970
Where does it come from?
77
00:08:35,679 --> 00:08:37,419
We talked about this before.
78
00:08:37,570 --> 00:08:43,720
You will fall into this trap if you put scandal next line ahead of next into next double next long or
79
00:08:43,720 --> 00:08:44,730
scandal next.
80
00:08:45,520 --> 00:08:49,240
So we're going to delete the code we have so far or you can comment it out if you want.
81
00:08:49,240 --> 00:08:49,840
It's up to you.
82
00:08:50,650 --> 00:08:54,010
I want to start by showing you the trap and explaining why it happens.
83
00:08:57,930 --> 00:09:03,780
So I'm going to ask the user to enter a no print, please enter a no, then I'm going to pick up the
84
00:09:03,780 --> 00:09:05,430
number with scanned nexted.
85
00:09:17,360 --> 00:09:19,430
And we ask the user to enter some text.
86
00:09:25,620 --> 00:09:28,830
And I'll pick up the text with scanned next line.
87
00:09:34,630 --> 00:09:37,360
Don't forget, stand up close, I shouldn't have removed it.
88
00:09:38,270 --> 00:09:40,250
In any case, I'm going to run this code.
89
00:09:46,560 --> 00:09:54,060
And it seems to skip scan next line, or is it what's really happening is that scan next and picks up
90
00:09:54,060 --> 00:09:57,150
the number, but the line isn't over and scanned.
91
00:09:57,150 --> 00:10:01,490
The next line starts here and it says, OK, I guess this is the next line.
92
00:10:02,040 --> 00:10:06,360
So it reads the rest of the current line, which ends up being completely empty.
93
00:10:06,900 --> 00:10:07,810
So you're scanned.
94
00:10:07,810 --> 00:10:10,650
The next line is actually wasted on an empty line.
95
00:10:11,490 --> 00:10:18,630
And we can fix this issue by calling a throwaway scan next line just before our real scanned next line.
96
00:10:20,860 --> 00:10:22,420
So if we rerun this code.
97
00:10:32,620 --> 00:10:33,610
Everything works out.
98
00:10:36,470 --> 00:10:42,590
What's happening is that next in picks up the integer and the throwaway next line is wasted on the rest
99
00:10:42,590 --> 00:10:44,270
of the current line, which is empty.
100
00:10:44,690 --> 00:10:49,930
And then the following Scandi next line is ready to read all of the values on the next line.
101
00:10:50,330 --> 00:10:52,280
In this case, it reads every sentence.
102
00:10:52,310 --> 00:10:53,360
I love Java.
103
00:10:59,960 --> 00:11:05,990
These methods use the delimiter pattern to read your data scanned next and next long necks double and
104
00:11:05,990 --> 00:11:10,210
next, that is, they skip empty space and they read the next input.
105
00:11:10,910 --> 00:11:13,460
Now scan the next line doesn't care about delimiters.
106
00:11:13,640 --> 00:11:15,350
It reads everything line by line.
107
00:11:15,350 --> 00:11:18,140
And that's why it's liable to falling into a trap.
108
00:11:18,980 --> 00:11:25,040
And the trap occurs when you put Eskandar next line ahead of any method that follows the delimiter pattern
109
00:11:25,370 --> 00:11:28,310
next and next double next log or next.
110
00:11:29,030 --> 00:11:33,830
All of these methods only pick up the values that they're interested in and they leave us with an empty
111
00:11:33,830 --> 00:11:36,380
line that scan the next line is wasted on.
112
00:11:36,710 --> 00:11:41,570
And so the solution is to add a throwaway next line just before your real next line.
11212
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.