@Nuerotronic because the probability of getting one of the numbers 1-6 on a dice is 1/6. If you augment the number of throws to lets say 1000000 youll get 1/6 * 1000000 = 166666 with slight variations. But if you let it loop infinite times the variations will disapear. So for 1000 throws the average frequency is 1/6 * 1000 = 166 with slight variations.
around 2:15 .. It doesn't loop it 1000 times it loops it 999 since you put roll<1000 with it starting at 1. If it was starting at 0 or roll<=1000 then it would be 1000 times.
@thenewboston Hey Bucky I think you made a mistake at 2:10, you wanted to roll the dice 1000 times yet you put the second parameter "roll<1000" remember your first parameter shows that it starts counting from 1 and not from 0, therefore you really did 999 rolls not 1000!
If you wanted 1000 then you should have put like in your previous tutorials "roll<=1000" or simply leave the second parameter as it is but change the first one to "roll=0"
I am a C++ Programmer, just came to learn some Java.
What is the difference between the rand.nextInt(6) and Math.random*(6) ? Also what does the .nextInt method do, and can it be applied to anything else?
@ThatRandomNoob They accomplish the same thing, the only difference is that Math.random does not need you to instantiate an object first (like rand) before you use it. The method .nextInt is a method of both the Random and Scanner classes. When used with the Scanner class, it looks for the next integer that the user input, but with the Random class, it generates a random integer within the range you gave.
first i was learning c++, it took me forever to learn somting, then i met this tutorials, now i'm learning java, because it's a loth easyer to follow you, then a lame text!
i just had a quick thought ... for all these programs is Bucky using the samples in the book "Java How To Program" by Deitel & Deitel??? cause I have that book and buckys examples are the exact same that are in the book
Thank you. My program was only showing one roll, with no errors. I checked the code in the forums and found an extra ; I will never be able to thank you enough for these videos!
@GeorgeUnitt It's just probabilities. IF you roll a dice a thousand times, every number is going to come up an unknown number of times.
However, there is a certain probability to it. You will most likely not roll a "1" only once. As a matter of fact, in a perfect world, all the numbers would show up 166.6 times. (thousand rolls divided by six numbers = 166.6-ish).
@asemahOnline So all the numbers are three digits because the probability is such. If you set the program to roll only a 100 dice, you will (probably) only get two digit numbers, but you MIGHT get a single digit if the probability is such.
When i put the face variable in "for(int face....)" it does not recognize this as a variable. Any suggestions? I have copied the exact same code as bucky's but it won't run.
@TheFredemand it should work, make sure your code is as follows for(int face=0;face<arrayName.length();face++){ "inside here is what you want looped."}
@TheFredemand and if that doesnt work you can always initialize the reference variable face in your public class (before the main method).. like this int face; or int face=0; either way works
I needed to put twice the video, not because I didn't understand, but because I got curious and put the audio subtitles by google to see what the did, try it, you are going to laugh a little while.
If anyone is confused i would suggest going and watching not just one of these tutorials (one "series") but watching one series until it gets too confusing because you don't really know/understand what was taught in the previous tutorials so instead of going back and watching them again the old ones which you probably wouldn't pay attention to anyway since you have already seen it but instead go to a different language playlist and solidify your understanding of the basics / previous material.
meanwhile, my teacher by following a book of David Shmidt, learnt us a bit GUI from JFrame a way before we learn for Loop, ever before "if statement". that is awkward right ?
@TheManifest121 He defined it in the last for loop. It's in the freq array because face goes from 1 to 6 so when he writes System.out.println(face+"\t"+freq[face]); it will print
1 (because face =1) and then whatever number freq[1] is.
2 (because face =2) and then whatever number freq[2] is etc.
Ugh 30 tutorials in a day, time to sleep :D, great tutorials bucky! One thing that helps alot is to actually write notes, I just check my notes reguarly to make sure I don't forget something.
a much easier way to do the random number, where you don't have to import anything is just type: (int)(Math.random()*6+1);
This does the same thing but much quicker. The "int" rounds off the number to be a whole number, and the +1 again is because Math.random is a random number bigger then 0 and less than 1.
ah ok the ++ increments the array freqs value so, random generates a random index number to which the ++ should be added to. Once the first for loop finishes all the indexes will have been increased and then the program continues.
++freq[1+rand.nextInt(6)]; is confusing me... so in the [] a random number between 1 to 6 will be set right? so ++freq[1]; would equal freq[2] ? what does ++ increment, the index?
@o0Richard ok...the 1+rand.nextInt(6) gives the array a index value of 1-6(Face) instead of 0-5. the ++freq[] adds 1 point to a index value(Face 1-6), for each time the random number generator hits a value anywhere between 1-6. Ex. if rand.nextInt(6)+1 gives 4, ++freq[] adds a point to the index [4].
It's not mandatory to put "7" for the number of indexes in the" freq array", you can put "6" but at the last line put "face+1", same effect but optimization of the length of array.
@ChrisTheBest1992 The first for() adds one to the array value that is hit by the 1+ramd.nextInt(6) <- It uses 6 cause theres only 6 numbers on a cube and a +1 at the beggining because it counts from 0-5. The next for() only displays the "table" with the values. Good luck.
if everyone that watched this sended bucky 10 euros each, then he would earn 1113467 euros becouse hes a greate teacher, wich we would pay Much money if we would have to find someone else that is just as him, he linked hes paypal on hes youtube page, i´ll send 10 euros as soon as i can, like this so we get everyone else to also send this
@TheVenumas The reason he added the ++freq[] is because, say for example
We know that freq[2] has initial value of 0 because it has never occurred. Now the face 2 comes up and we need to increase the value of freq[2] by 1. Initially freq[2] =0 but now after the face 2 showed up we increase it by 1 and it becomes freq[2] = 1. We use this increment operator to increase the value by 1. What we are doing is saying freq[2] = freq[2] + 1. Hope it makes sense.
i ddnt understand where we write to show the value between 1-1000... we only give the value to the no of loops????? roll<1000...but where we write to show in between 1000???????i dnt get it maan.
@BSstudioz You could assign a random block to a random coordinate (x, y, z), but Minecraft terrain isn't random. There's randomness, but with constraints. No diamonds above X. Bedrock always at X. No floating blocks Etcetera.
@Quentello \t means tab, the backslash is an escape character that tells java that the next character isnt part of what is inside the " " so it doesnt print the t, and also does something about it, there is a list of what each character does, for example a \n would skip a line, you can try it out.
To those commenting that it has to be <= and not just <, you are only half right. What we are trying to do is get random, key word here, numbers. You ARE getting 6 random numbers, changing it around will still yield 6 RANDOM numbers, so there really is no point lol.
@BearZzZz1 It's probably better to leave it at 1 and change the 2nd argument to <=1000, if it's <1000, then it'll jump out of the loop once roll reaches 1000, giving the sum of the freq as 999 whereas with <=1000, it will jump out of the loop at 1001, giving the sum as 1000 which is what we are wanting.
Oh btw this prgram is GREAT thanks bucky:) but it will alwaaaayys be 1 digit off unless you put roll<=1000; it needs the "equal to" sign if you want it to be exact, no biggy.
Hahaha I just imported the Scanner and added it as my variable in my first "for" statment so you can type the number of rolls you want it to do, i typed in a billionXD took like 2 minutes
You can do this so that you don't have to make an array of seven and waste space:
import java.util.Random;
public class practice12 { public static void main(String args[]) { Random rand = new Random(); int freq[] = new int[6]; for (int roll = 1; roll < 1000; roll++) { ++freq[rand.nextInt(6)]; } System.out.println("Face\tFrequency"); for (int face = 0; face < freq.length; face++) { System.out.println(face + 1 + "\t" + freq[face]); } }
Awesome! I thought this part was a bit tricky to understand, but after coding it myself and commenting exactly what each line of code did. It cleared up and I must say that this was a very neat code! :-)
I use DrJava as my scripting program, it's got the same features as Eclipse it just doesn't show the different kinds of codes while I'm typing or highlighting a written code, otherwise DrJava is a very good and decent java scripting program to start with.
If you guys don't want to use eclipse you can use BlueJ its pretty good for beginners because it color codes the classes and methods, but I would recommend eclipse.
Love the tutorials, they are great! Thanks! but I did find an error...
2:00 to roll exactly 1000 times you would need to start roll at 0 until roll<1000. Or, you could set roll to 1 and roll until roll<=1000. Otherwise you only roll 999 times. This is a common error in programming, but otherwise a great tutorial!
I think the below code would be better to understand for beginners. for (int counter=1;counter<=10;counter++){ int random = rand.nextInt(6)+1; System.out.println("the random number rolled is: " + random); freq[random] += 1; }
WHAT THE HECK? WHY IS TELLING ME " 'face' cannot be resolved to a variable"???????????? And YES I spelled them all the same way, with correct syntax.....
The only thing that upsets me with these tutorials is that the language used to describe what is going on is dumbed down. Its all good though it should be like that. I feel like my ability to describe and truly understand everything that is actually going is dumbed down a bit.
@BriceOnIce This really doesn't matter since this is only beginner type Java programming. It's not like anyone looking at this will be producing major programs within the next few years. It's only about the how functions can be used, not how he uses them
Actually, this only rolling the die 999 times. For it to roll exactly 1,000 times, you need to put "roll<=1000" in the parameters instead of "roll<=1000". This is because he started it at 1. since 1000 is not less than 1000, it goes from 1-999, only rolling 999 times. You could also change "int roll = 1" to "int roll = 0" and have the same effect.
On my comment, I was just compared Eclipse and Notepad. Sure you can use Netbeans. ;)
Also, not too sure about BlueJ. I've never heard of it. It's usually just what you prefer. But I recommend advanced programs like Netbeans or Eclipse.
The only part I don't get is why the very last line is +freq[face]. Why is face in the brackets of our frequency array? I've got all of it down up to this point ;)
@seed419 Face goes from 1 - 6 in the for loop the first time he put face System.out.println(Face + " " it only counted from 1 - 6 which also tells us the element of the array, then if its the plus before the freq your confused about, when you tell system to print a variable or tab or any thing you have to use the plus sign to divide what your adding like 2 + 2 + 2 +2 or java will thing those things are together when there not,.
@seed419 and if your confused because he put ''face'' in the array arrgument bracket, thats because face goes from 1 - 6 as i said, so it will make the freq array print 6 of its elements. :)
@thenewboston: You think should have explained why you do ++freq[1+rand.nextInt(6)]; and not freq[1+rand.nextInt(6)]++; or that you wrote that last for loop face<freq.length note the < not <= etc. These tidbits if you don't learn what they do will create bugs a junior programmer is not aware of!
@ballen900 int freq[] = new int[7] just creates an array with 7 int values (which are currently null or undefined), whereas int freq[] = {0,1,2,3,4,5,6} creates a 7 int array with the values defined as 0,1,2,3,4,5, and 6.
thanks for pointing out explicitly what you want to teach us. thanks for pointing out what the most important line of code is. those two things help because it makes your tutorial efficient as it is very structured. please dont hesitate to give a detailed discussion as to why you consider such line the most important piece of code. look forward to look at other tutorials of yours. thanks . very didactic.
im using dr. java. how do i download the java.util.random into dr. java
thanks for pointing out explicitly what you want to teach us. thanks for pointing out what the most important line of code is. those two things help because it makes your tutorial efficient as it is very structured. please dont hesitate to give a detailed discussion as to why you consider such line the most important piece of code. look forward to look at other tutorials of yours. thanks . great work. very didactic
Oh boy, finally made it to number 30 lol. Wonder how many of these there are.
Favorlock 9 hours ago
Face Frequentcy
1 [I@133c5982
2 [I@133c5982
3 [I@133c5982
4 [I@133c5982
5 [I@133c5982
6 [I@133c5982
what to do? D;
GwnArne 5 days ago
Why are all the randomly generated numbers always less than 200?
Nuerotronic 5 days ago
@Nuerotronic because the probability of getting one of the numbers 1-6 on a dice is 1/6. If you augment the number of throws to lets say 1000000 youll get 1/6 * 1000000 = 166666 with slight variations. But if you let it loop infinite times the variations will disapear. So for 1000 throws the average frequency is 1/6 * 1000 = 166 with slight variations.
moohboo 3 days ago
Face Frequency
1 [I@2e0b08f1
2 [I@2e0b08f1
3 [I@2e0b08f1
4 [I@2e0b08f1
5 [I@2e0b08f1
6 [I@2e0b08f1
and my code is h ttp://pa stie.or g/35 127 86 Can anyone help me out?
SergeantBalthazar 6 days ago in playlist Java (Beginner) Programming Tutorials
@SergeantBalthazar Nevermind I just did a derp move. Figured it out :)
SergeantBalthazar 6 days ago in playlist Java (Beginner) Programming Tutorials
that'll do pig, that'll do
ironflange2000 6 days ago
cant trick me
it's not a thousand times
villainy07 1 week ago in playlist Java (Beginner) Programming Tutorials
around 2:15 .. It doesn't loop it 1000 times it loops it 999 since you put roll<1000 with it starting at 1. If it was starting at 0 or roll<=1000 then it would be 1000 times.
ShaneCopseysTV 1 week ago 2
this one's pretty cool :D thanks
jesusshank 1 week ago
Face Frequency
1 182
2 182
3 161
4 167
5 154
6 153
i didnt get a 0...
dragonthewatcher 2 weeks ago
im confused... how do i make a delay?i tried doing a for loop with for(int counter=0;counter<=99999999999;counter++){
}
System.out.println("suddenly a hand shoots from the mist") but it still does it instantly....
dragonthewatcher 2 weeks ago
beattie282 2 weeks ago in playlist Java (Beginner) Programming Tutorials
This has been flagged as spam show
@thenewboston Hey Bucky I think you made a mistake at 2:10, you wanted to roll the dice 1000 times yet you put the second parameter "roll<1000" remember your first parameter shows that it starts counting from 1 and not from 0, therefore you really did 999 rolls not 1000!
If you wanted 1000 then you should have put like in your previous tutorials "roll<=1000" or simply leave the second parameter as it is but change the first one to "roll=0"
I am a C++ Programmer, just came to learn some Java.
FCFZ 2 weeks ago in playlist Java (Beginner) Programming Tutorials
Comment removed
FCFZ 2 weeks ago in playlist Java (Beginner) Programming Tutorials
What is the difference between the rand.nextInt(6) and Math.random*(6) ? Also what does the .nextInt method do, and can it be applied to anything else?
ThatRandomNoob 2 weeks ago in playlist Java (Beginner) Programming Tutorials
@ThatRandomNoob They accomplish the same thing, the only difference is that Math.random does not need you to instantiate an object first (like rand) before you use it. The method .nextInt is a method of both the Random and Scanner classes. When used with the Scanner class, it looks for the next integer that the user input, but with the Random class, it generates a random integer within the range you gave.
Spydurz 2 weeks ago
first i was learning c++, it took me forever to learn somting, then i met this tutorials, now i'm learning java, because it's a loth easyer to follow you, then a lame text!
ecence123 2 weeks ago
i just had a quick thought ... for all these programs is Bucky using the samples in the book "Java How To Program" by Deitel & Deitel??? cause I have that book and buckys examples are the exact same that are in the book
TheGame1083 3 weeks ago in playlist Java (Beginner) Programming Tutorials
Comment removed
FantasticBooty 2 weeks ago in playlist Java (Beginner) Programming Tutorials
@TheGame1083 ok, but all must have learned java somewhere and he teaches us for free
gustavboll1 2 weeks ago
you wrote roll<1000, not roll<=1000, so you only rolled it 999 times;
anyway, nice lesson, as always, thanks.
iurisegtovisk 3 weeks ago
Thank you. My program was only showing one roll, with no errors. I checked the code in the forums and found an extra ; I will never be able to thank you enough for these videos!
Kenilishus 4 weeks ago
haha i made that counter a view tutorials earlier, but much more complicated ^^
Hellrun1 1 month ago
Why are they always 3 digit numbers?! Is there something I've missed?
GeorgeUnitt 1 month ago in playlist Java (Beginner) Programming Tutorials
@GeorgeUnitt It's just probabilities. IF you roll a dice a thousand times, every number is going to come up an unknown number of times.
However, there is a certain probability to it. You will most likely not roll a "1" only once. As a matter of fact, in a perfect world, all the numbers would show up 166.6 times. (thousand rolls divided by six numbers = 166.6-ish).
asemahOnline 1 month ago in playlist Bucky's Java Tutorial
This has been flagged as spam show
@asemahOnline So all the numbers are three digits because the probability is such. If you set the program to roll only a 100 dice, you will (probably) only get two digit numbers, but you MIGHT get a single digit if the probability is such.
asemahOnline 1 month ago in playlist Bucky's Java Tutorial
Comment removed
asemahOnline 1 month ago in playlist Bucky's Java Tutorial
this tutorial caught me for like 3 days
COD5252 1 month ago
You and I both got 3 179 times!
itsArtfulME 1 month ago
hopefully i see you next tutorial and yes hopefully he saw us every tutorial
COD5252 1 month ago
i always get confused with \ and / ughhhhh !
killavidsz1230 1 month ago in playlist Java (Beginner) Programming Tutorials
When i put the face variable in "for(int face....)" it does not recognize this as a variable. Any suggestions? I have copied the exact same code as bucky's but it won't run.
TheFredemand 1 month ago 2
@TheFredemand it should work, make sure your code is as follows for(int face=0;face<arrayName.length();face++){ "inside here is what you want looped."}
blkbearh2o 1 month ago in playlist Java (Beginner) Programming Tutorials
@TheFredemand and if that doesnt work you can always initialize the reference variable face in your public class (before the main method).. like this int face; or int face=0; either way works
blkbearh2o 1 month ago in playlist Java (Beginner) Programming Tutorials
I needed to put twice the video, not because I didn't understand, but because I got curious and put the audio subtitles by google to see what the did, try it, you are going to laugh a little while.
MrChearlie2 1 month ago in playlist Java Programming Tutorials
Comment removed
nishantve1 1 month ago
Confused?? go back and watch the 26th tutorial - Random number generator , hopefully will clear things up
nishantve1 1 month ago
Comment removed
Ayplus 1 month ago
holy crap i got it
yoyos41 1 month ago in playlist Java Programming Tutorials
If anyone is confused i would suggest going and watching not just one of these tutorials (one "series") but watching one series until it gets too confusing because you don't really know/understand what was taught in the previous tutorials so instead of going back and watching them again the old ones which you probably wouldn't pay attention to anyway since you have already seen it but instead go to a different language playlist and solidify your understanding of the basics / previous material.
KristopherSw 1 month ago
meanwhile, my teacher by following a book of David Shmidt, learnt us a bit GUI from JFrame a way before we learn for Loop, ever before "if statement". that is awkward right ?
tonilocoable 1 month ago
21 more and we get the JFrame and can create popup boxes! :D
HTMLMINECRAFTGUYJAVA 1 month ago 3
thumps up if you have watched all the tutorials before this one
zaidalyafey 1 month ago 160
epic phrase : it'll do pig, it'll do...
afkin9 1 month ago
Why is face inside the freq array if he didn't define it! I don't get it, I'm confused :S
TheManifest121 2 months ago
@TheManifest121 "for(int face=0"
TeamCorder 1 month ago
@TheManifest121 he defined it in the for loop.
TakeshiTikanoTW 1 month ago
@TheManifest121 He defined it in the last for loop. It's in the freq array because face goes from 1 to 6 so when he writes System.out.println(face+"\t"+freq[face]); it will print
1 (because face =1) and then whatever number freq[1] is.
2 (because face =2) and then whatever number freq[2] is etc.
I hope that makes some sort of sense.
Mtc529 1 month ago
@Mtc529 Oh, thank you :)
TheManifest121 1 month ago
pls tell me, what is difference between: ++freq and freq++ ...why are ++ before freq? i really dont get that? and why freq needs to have ++?
vardicbojan 2 months ago
@vardicbojan
freq = 1
++freq adds 1 to that freq. (freq = 2)
freq++ will add 1 to the next freq you use. (1st time: freq = 1 | 2nd time: freq = 2)
xXZarlachXx 2 months ago in playlist Java Programming Tutorials
Shit just got serious.
And confusing.
C0GSniper 2 months ago in playlist Java Programming Tutorials 2
Comment removed
lagomstor 2 months ago
love how this video has more views than the tutorial before it lol :)
TzKet4m 2 months ago in playlist More videos from thenewboston
my for loop went...OVER NIINE THOOOUUUSAND TIMES rand<9001
mcfundash1 2 months ago in playlist Java Programming Tutorials
dafuck?
xJustas 2 months ago
Bucky, I would appreciate if you created a tutorial covering the sequential search, selecand binary search algorithms.
idiotrun1997 2 months ago in playlist Java Programming Tutorials
The new boston should merge with khan academy
alvajum 3 months ago 6
This stuff is getting really complicated. I am assuming it gets even harder from here on in. I hope not. I think I am in trouble. I am the only one?
forexdragon 3 months ago
Ugh 30 tutorials in a day, time to sleep :D, great tutorials bucky! One thing that helps alot is to actually write notes, I just check my notes reguarly to make sure I don't forget something.
thehikfar 3 months ago in playlist Java Programming Tutorials 2
@thehikfar lol I download all the videos of bucky that I watch just to avoid making notes xD
jussipejulliano 2 months ago
a much easier way to do the random number, where you don't have to import anything is just type: (int)(Math.random()*6+1);
This does the same thing but much quicker. The "int" rounds off the number to be a whole number, and the +1 again is because Math.random is a random number bigger then 0 and less than 1.
kdclmn 3 months ago
@kdclmn
Thanks for the tip. It is always good to learn things the manual way I guess so you have the background.
forexdragon 3 months ago
ah ok the ++ increments the array freqs value so, random generates a random index number to which the ++ should be added to. Once the first for loop finishes all the indexes will have been increased and then the program continues.
o0Richard 3 months ago
++freq[1+rand.nextInt(6)]; is confusing me... so in the [] a random number between 1 to 6 will be set right? so ++freq[1]; would equal freq[2] ? what does ++ increment, the index?
o0Richard 3 months ago
@o0Richard ok...the 1+rand.nextInt(6) gives the array a index value of 1-6(Face) instead of 0-5. the ++freq[] adds 1 point to a index value(Face 1-6), for each time the random number generator hits a value anywhere between 1-6. Ex. if rand.nextInt(6)+1 gives 4, ++freq[] adds a point to the index [4].
koenigsegg1000 3 months ago 3
@koenigsegg1000 thanks that helps
reemstar1986 2 months ago
@koenigsegg1000
wow i understand now! Thank you so much <3
90158160 1 month ago
It's not mandatory to put "7" for the number of indexes in the" freq array", you can put "6" but at the last line put "face+1", same effect but optimization of the length of array.
AlephAriadiate 3 months ago
I remember when i was confused wit System.out.println....
blamsam001 3 months ago in playlist Java Programming Tutorials 105
@blamsam001 how did you get confused by that?
caseyguitarist 1 month ago in playlist Java Programming Tutorials
i love you
Ubaroo 3 months ago in playlist Java Programming Tutorials
30 down and i don't know how many to go then i'll be applying for work, thanks bucky!
elvisniperx 3 months ago in playlist More videos from thenewboston
@elvisniperx there is like 80+
psntanner11man 3 months ago in playlist Java Programming Tutorials
I hereby propose a new grade:
Face++
Aflacduck247 3 months ago in playlist Java Programming Tutorials
@chrisTheBest1992 IM me
nvarun300 3 months ago
I CANT UNDERSTAND THIS PROGRAM,CAN SOMEONE HELP ME?
ChrisTheBest1992 3 months ago
@ChrisTheBest1992 The first for() adds one to the array value that is hit by the 1+ramd.nextInt(6) <- It uses 6 cause theres only 6 numbers on a cube and a +1 at the beggining because it counts from 0-5. The next for() only displays the "table" with the values. Good luck.
-Killman2639
killman2639 3 months ago
For those how have difficulties to understand that program let replace: ++freq[1+rand.nextInt(6)]
by:
position=1+rand.nextInt(6);
freq[position] = freq[position]+1;
Where position is declared before the for loop as follow:
int position;
But be aware that the best solution is the bucky one.
AlephAriadiate 4 months ago
I did this two tutorials ago :)
tehnoobguy1 4 months ago in playlist TheNewBoston - Java Programming
@tehnoobguy1
OK, sorry, I didn't see it :-)
AlephAriadiate 3 months ago
Doing my math,science HW and making an array at the same time. Hardcore...
TheMcdog2 4 months ago
Thirty quick ones...
thanks a bunch!
kjellan1000 4 months ago
Lol listen 0:15-0:17 ahhhahaahahahahahaaa thumbs up if you laughed :D
DontDestroyTheHype 4 months ago
@DontDestroyTheHype What?
MinecraftCreators 4 months ago in playlist Java Programming Tutorials
it must be roll < 1001 in order to roll 1000 times, right?
freq <= face outputs an error and letting face start at 0 results in face and frequency being 0 which is not valid for a die.
TheCarmacon 4 months ago
if everyone that watched this sended bucky 10 euros each, then he would earn 1113467 euros becouse hes a greate teacher, wich we would pay Much money if we would have to find someone else that is just as him, he linked hes paypal on hes youtube page, i´ll send 10 euros as soon as i can, like this so we get everyone else to also send this
simme337 4 months ago
I dont understand why he added "++" just before freq[] .
TheVenumas 4 months ago
@TheVenumas The reason he added the ++freq[] is because, say for example
We know that freq[2] has initial value of 0 because it has never occurred. Now the face 2 comes up and we need to increase the value of freq[2] by 1. Initially freq[2] =0 but now after the face 2 showed up we increase it by 1 and it becomes freq[2] = 1. We use this increment operator to increase the value by 1. What we are doing is saying freq[2] = freq[2] + 1. Hope it makes sense.
RaqibulHayder 4 months ago
Your code is wrong. Change face to start at 0, or change face<freq to face<=freq in order to actually roll 1000 times.
TheDrCN 4 months ago
i ddnt understand where we write to show the value between 1-1000... we only give the value to the no of loops????? roll<1000...but where we write to show in between 1000???????i dnt get it maan.
gadsfsd 4 months ago
episodes 1-30 in one might...
IamMclovin247 5 months ago
@BSstudioz You could assign a random block to a random coordinate (x, y, z), but Minecraft terrain isn't random. There's randomness, but with constraints. No diamonds above X. Bedrock always at X. No floating blocks Etcetera.
ihatehavingthis 5 months ago
Why is there a t in front of Frequency - System.out.println("Face\tFrequency");?
Thanks
Quentello 5 months ago
@Quentello "\t" means tab.
killroy7777 5 months ago in playlist More videos from thenewboston
@Quentello \t means tab, the backslash is an escape character that tells java that the next character isnt part of what is inside the " " so it doesnt print the t, and also does something about it, there is a list of what each character does, for example a \n would skip a line, you can try it out.
Xeinnex1 5 months ago
Nice set of tutorials. Thanks for taking the time to do them.
vladvladSM 5 months ago
I don't know what I did wrong. I didn't get the same numbers :'( someone HELP!
death2link 5 months ago in playlist Java Programming Tutorial
@death2link i guess because it's random, so you won't get the exact numbers with others CMIIW
soel87 5 months ago
@death2link lol its RANDOM so obviously you won't get the same numbers as him.
redjr242 5 months ago
Bucky For PRESIDENT!
turtlecat77 5 months ago
@turtlecat77 Bucky for supreme overlord of the universe.
SocialDisobediance 5 months ago
30 first tutorials first day ! Awwww Yeaah ;D
MartysAdventure 5 months ago in playlist Flere videoer fra thenewboston
everytime I'm on the verge of giving up on java and being completely lost, I just come to bucky's tutorials and everything makes sense again.
System.out.println("Thank you bucky, you're awesome");
Artizzy 5 months ago
btw you only rolled 999 times lol
Morcous16 6 months ago in playlist JAVA Tutorial (The New Boston) 67
Comment removed
bwoodlyrics 2 months ago in playlist Java Programming Tutorials
@Morcous16 that is because he started roll at 1 and didn't use roll <= 1000, so he would end up rolling 999 times
bwoodlyrics 2 months ago in playlist Java Programming Tutorials
@bwoodlyrics i know...
Morcous16 2 months ago
help this man and donate him, if you dont want to spend out money click on the advertisement on his website: thenewboston(dot)com
n1c313a 6 months ago
To those commenting that it has to be <= and not just <, you are only half right. What we are trying to do is get random, key word here, numbers. You ARE getting 6 random numbers, changing it around will still yield 6 RANDOM numbers, so there really is no point lol.
RazorSRaider 6 months ago
really thanks for provinding this totorial......
csharma4u1 6 months ago
LAAAAAWL
listen at 0:16
3dstiffler 6 months ago in playlist TheNewBoston - Java Programming 3
Excuse me bucky, but u got something wrong there:
int roll is equal to 0 not 1, if you calculate the sum of the face's frequencys it'll be equal to 999 and not 1000.
i hope this helped to the viewers and they corrected it.
thumbs up so everyone can see this.
BearZzZz1 6 months ago
@BearZzZz1 It's probably better to leave it at 1 and change the 2nd argument to <=1000, if it's <1000, then it'll jump out of the loop once roll reaches 1000, giving the sum of the freq as 999 whereas with <=1000, it will jump out of the loop at 1001, giving the sum as 1000 which is what we are wanting.
kazcjow 6 months ago
Comment removed
zeusprp 6 months ago in playlist Java Programming Tutorials
took me a bit, but i fully understand the programming behind this. i makes sense to me :D
Aaronster8 6 months ago
Oh btw this prgram is GREAT thanks bucky:) but it will alwaaaayys be 1 digit off unless you put roll<=1000; it needs the "equal to" sign if you want it to be exact, no biggy.
JPxKillz 6 months ago
Hahaha I just imported the Scanner and added it as my variable in my first "for" statment so you can type the number of rolls you want it to do, i typed in a billionXD took like 2 minutes
Type number of rolls:
1000000000
Face Frequency
1 166663871
2 166684546
3 166676548
4 166662082
5 166659480
6 166653472
JPxKillz 6 months ago 2
You can do this so that you don't have to make an array of seven and waste space:
import java.util.Random;
public class practice12 { public static void main(String args[]) { Random rand = new Random(); int freq[] = new int[6]; for (int roll = 1; roll < 1000; roll++) { ++freq[rand.nextInt(6)]; } System.out.println("Face\tFrequency"); for (int face = 0; face < freq.length; face++) { System.out.println(face + 1 + "\t" + freq[face]); } }
}
Mranjosh 6 months ago
why is the total of the numbers 999??
hotketchup99 6 months ago
Awesome! I thought this part was a bit tricky to understand, but after coding it myself and commenting exactly what each line of code did. It cleared up and I must say that this was a very neat code! :-)
Lucke189 7 months ago
This was probably the hardest video ive watched you made but when you explained in the end i finnaly understood
dtgonzalez1 7 months ago
I use DrJava as my scripting program, it's got the same features as Eclipse it just doesn't show the different kinds of codes while I'm typing or highlighting a written code, otherwise DrJava is a very good and decent java scripting program to start with.
qbblast 7 months ago
i have one earphone in on the left ear and my hand on the right ear so the tutorial dosent go staight through my ear and says in the brain!
GeezerGameGuideZ 7 months ago
Hey, 160+158+181+168+181+151=999 and you told us dice rolled 1000 times not 999 times
poyzz330 7 months ago
@poyzz330 Remember the computer starts counting from zero
Tbroman 7 months ago
If you guys don't want to use eclipse you can use BlueJ its pretty good for beginners because it color codes the classes and methods, but I would recommend eclipse.
k24bfan 7 months ago
Love the tutorials, they are great! Thanks! but I did find an error...
2:00 to roll exactly 1000 times you would need to start roll at 0 until roll<1000. Or, you could set roll to 1 and roll until roll<=1000. Otherwise you only roll 999 times. This is a common error in programming, but otherwise a great tutorial!
mrhozer 7 months ago 3
@mrhozer off by one errors should always be covered in beginner tutorials... they happen even to the pros
matthewdoucette 7 months ago
@mrhozer thank you so much that helped alot :)
hotketchup99 6 months ago
wow...I did this without watching this and I did it a lot different.
seed419 7 months ago in playlist Bucky's Java Tutorial
Don't you wish your girlfriend was a freq[] like me?
npacebg 8 months ago
I think the below code would be better to understand for beginners. for (int counter=1;counter<=10;counter++){ int random = rand.nextInt(6)+1; System.out.println("the random number rolled is: " + random); freq[random] += 1; }
fkashem1986 8 months ago
WHAT THE HECK? WHY IS TELLING ME " 'face' cannot be resolved to a variable"???????????? And YES I spelled them all the same way, with correct syntax.....
NehiThompson 8 months ago
@NehiThompson copy and paste it here
funnyb0y3000 8 months ago
The only thing that upsets me with these tutorials is that the language used to describe what is going on is dumbed down. Its all good though it should be like that. I feel like my ability to describe and truly understand everything that is actually going is dumbed down a bit.
XRenkoX 8 months ago
It actually rolls the dice 999 times
nevrahdavis 8 months ago
@nevrahdavis You can change that by doing for(int roll =1;roll<=1000;roll++)
Instead of for(int roll =1;roll<1000;roll++)
TheMerloc 8 months ago
lol "that'll do pig, that'll do" i love that movie its called babe (tahts the pigs name and the movies name)
basketballdude138 9 months ago
@BriceOnIce This really doesn't matter since this is only beginner type Java programming. It's not like anyone looking at this will be producing major programs within the next few years. It's only about the how functions can be used, not how he uses them
Gyohdon 9 months ago
int rnd = (int) ((Math.random()*6)+1);
threeclock 9 months ago
Actually, this only rolling the die 999 times. For it to roll exactly 1,000 times, you need to put "roll<=1000" in the parameters instead of "roll<=1000". This is because he started it at 1. since 1000 is not less than 1000, it goes from 1-999, only rolling 999 times. You could also change "int roll = 1" to "int roll = 0" and have the same effect.
ddg069 9 months ago
On my comment, I was just compared Eclipse and Notepad. Sure you can use Netbeans. ;)
Also, not too sure about BlueJ. I've never heard of it. It's usually just what you prefer. But I recommend advanced programs like Netbeans or Eclipse.
CODtheater 9 months ago
Hey Bucky, thanks for the great tutorials. I just noticed that in this video you 'roll' the dice 999 times instead of 1000. ;-)
ultimatebas 9 months ago
"name it freak or whatever..." hehe
ballen900 10 months ago
The only part I don't get is why the very last line is +freq[face]. Why is face in the brackets of our frequency array? I've got all of it down up to this point ;)
seed419 10 months ago
@seed419 Face goes from 1 - 6 in the for loop the first time he put face System.out.println(Face + " " it only counted from 1 - 6 which also tells us the element of the array, then if its the plus before the freq your confused about, when you tell system to print a variable or tab or any thing you have to use the plus sign to divide what your adding like 2 + 2 + 2 +2 or java will thing those things are together when there not,.
sonicthehedgehogxp 10 months ago
@seed419 and if your confused because he put ''face'' in the array arrgument bracket, thats because face goes from 1 - 6 as i said, so it will make the freq array print 6 of its elements. :)
sonicthehedgehogxp 10 months ago
yes i know that now and don't need any more answers please...
ballen900 10 months ago
It will sum 999 times only, hehe, roll should be <= 1000
ptchau2003 10 months ago
@ptchau2003 another alternative would be changing ++freq[1+rand.nextInt(6)] to freq[1+rand.nextInt(6)]++ i guess?
WebPicMan 9 months ago
@thenewboston: You think should have explained why you do ++freq[1+rand.nextInt(6)]; and not freq[1+rand.nextInt(6)]++; or that you wrote that last for loop face<freq.length note the < not <= etc. These tidbits if you don't learn what they do will create bugs a junior programmer is not aware of!
nutelina 10 months ago
Comment removed
ballen900 10 months ago
@ballen900 int freq[] = new int[7] just creates an array with 7 int values (which are currently null or undefined), whereas int freq[] = {0,1,2,3,4,5,6} creates a 7 int array with the values defined as 0,1,2,3,4,5, and 6.
kkurt5 10 months ago
@ballen900 : Very different, when you write like that you will have freq[0]=0, freq[1]=1, freq[2]=2 ... so on on first situation
second situation you will have freq[0]=0, freq[1]=0, .... freq[6]=0;
Think about it.
ptchau2003 10 months ago
Man his child is gonna go through pottty training fast
Khoaster 10 months ago
I liked all your videos so far.
2454014 11 months ago
i didn't get the part ++freq to the end, any one can help??
kotb90 11 months ago
@kotb90 the part with "1+rand.nextInt (6)"will give you a random number between 1 and 6 (see tutorial 29)
so, for example the random will give you ++freq[4].
remember that if you have variable "bucky" and you want to add 1 to the current value, you could do ++bucky to do so.
so when we do ++freq[4] we take the current value of freq[4], and add 1 to it. that way we count how many time the random finds "4" as an answer.
Tussengassed 10 months ago
could we write Random rand = new Random(rand>=1) or something like that in order to have all randoms except for 0?????
morog666 11 months ago
thanks for pointing out explicitly what you want to teach us. thanks for pointing out what the most important line of code is. those two things help because it makes your tutorial efficient as it is very structured. please dont hesitate to give a detailed discussion as to why you consider such line the most important piece of code. look forward to look at other tutorials of yours. thanks . very didactic.
im using dr. java. how do i download the java.util.random into dr. java
ranssff 11 months ago
thanks for pointing out explicitly what you want to teach us. thanks for pointing out what the most important line of code is. those two things help because it makes your tutorial efficient as it is very structured. please dont hesitate to give a detailed discussion as to why you consider such line the most important piece of code. look forward to look at other tutorials of yours. thanks . great work. very didactic
ranssff 11 months ago
oops i fugot... da loop strts frm 1... so da die rollz 999 tymz...
add ur results n ul gt 999!!!...
d3c0d3junky 11 months ago
@LadyDragon82105
In this xample da die rollz 1000 tymz...
Ckh it out usin a simple 'for' loop...
for(int i=0; i<10; i++)
the loop runz 10 tymz.... Giving the output 0-9...
bt whn its i<=10 it runz 11 tymz(countin 0)...
d3c0d3junky 11 months ago
hey does anyone know how i would do this using math.random???
MissShauna1234 1 year ago
@MissShauna1234
Math.random() gives a value between 0 and 1, for example it might give 0.3525155425.
voidportal 1 year ago
It was really helpful but the die was rolled 999 times and not 1000. I think the roll variable should start from zero and not one.
obinnaokechukwu 1 year ago 3
@obinnaokechukwu It only rolls 999 bec. the loop 'roll< 1000' - if we wanted 1000 the loop would be 'roll <=1000'.
LadyDragon82105 1 year ago
@LadyDragon82105 It's rolling 998 times since it starts at 1, not 0.
Haroids 11 months ago