Added: 2 years ago
From: thenewboston
Views: 147,643
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (325)

Sign In or Sign Up now to post a comment!
  • Oh boy, finally made it to number 30 lol. Wonder how many of these there are.

  • Face Frequentcy

    1 [I@133c5982

    2 [I@133c5982

    3 [I@133c5982

    4 [I@133c5982

    5 [I@133c5982

    6 [I@133c5982

    what to do? D;

  • Why are all the randomly generated numbers always less than 200?

  • @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.

  • 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 Nevermind I just did a derp move. Figured it out :)

  • that'll do pig, that'll do

  • cant trick me

    it's not a thousand times

  • 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.

  • this one's pretty cool :D thanks

  • Face Frequency

    1 182

    2 182

    3 161

    4 167

    5 154

    6 153

    i didnt get a 0...

  • 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 public static void wait (int n){ long time0,ttime1; time0=System.currentTimeMillis­(); do{ time1=System.currentTimeMillis­(); } while (time1-time0<1000); } sorry about the dodgy formatting
  • Comment removed

  • 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

  • Comment removed

  • @TheGame1083 ok, but all must have learned java somewhere and he teaches us for free

  • you wrote roll<1000, not roll<=1000, so you only rolled it 999 times;

    anyway, nice lesson, as always, thanks.

  • 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!

  • haha i made that counter a view tutorials earlier, but much more complicated ^^

  • Why are they always 3 digit numbers?! Is there something I've missed?

  • @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).

  • Comment removed

  • this tutorial caught me for like 3 days 

  • You and I both got 3 179 times!

  • hopefully i see you next tutorial and yes hopefully he saw us every tutorial

  • i always get confused with \ and / ughhhhh !

  • 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.

  • Comment removed

  • Confused?? go back and watch the 26th tutorial - Random number generator , hopefully will clear things up

  • Comment removed

  • holy crap i got it

    

  • 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 ?

  • 21 more and we get the JFrame and can create popup boxes! :D

  • thumps up if you have watched all the tutorials before this one

  • epic phrase : it'll do pig, it'll do...

  • Why is face inside the freq array if he didn't define it! I don't get it, I'm confused :S

  • @TheManifest121 "for(int face=0"

  • @TheManifest121 he defined it in the for loop.

  • @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"+f­req[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 Oh, thank you :)

  • 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

    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)

  • Shit just got serious.

    And confusing.

  • Comment removed

  • love how this video has more views than the tutorial before it lol :)

  • my for loop went...OVER NIINE THOOOUUUSAND TIMES rand<9001

  • dafuck?

  • Bucky, I would appreciate if you created a tutorial covering the sequential search, selecand binary search algorithms.

  • The new boston should merge with khan academy

  • 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?

  • 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 lol I download all the videos of bucky that I watch just to avoid making notes xD

  • 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

    Thanks for the tip. It is always good to learn things the manual way I guess so you have the background.

  • 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].

  • @koenigsegg1000 thanks that helps

  • @koenigsegg1000

    wow i understand now! Thank you so much <3

  • 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.

  • I remember when i was confused wit System.out.println....

  • @blamsam001 how did you get confused by that?

  • i love you

  • 30 down and i don't know how many to go then i'll be applying for work, thanks bucky!

  • @elvisniperx there is like 80+

  • I hereby propose a new grade:

    Face++

  • I CANT UNDERSTAND THIS PROGRAM,CAN SOMEONE HELP ME?

  • @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

  • 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.

  • I did this two tutorials ago :)

  • @tehnoobguy1

    OK, sorry, I didn't see it :-)

  • Doing my math,science HW and making an array at the same time.  Hardcore...

  • Thirty quick ones...

    thanks a bunch!

  • Lol listen 0:15-0:17 ahhhahaahahahahahaaa thumbs up if you laughed :D

  • 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.

  • 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

  • I dont understand why he added "++" just before freq[] .

  • @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.

  • Your code is wrong. Change face to start at 0, or change face<freq to face<=freq in order to actually roll 1000 times.

  • 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.

  • episodes 1-30 in one might...

  • @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.

  • Why is there a t in front of Frequency - System.out.println("Face\tFreq­uency");?

    Thanks

  • @Quentello "\t" means tab.

  • @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.

  • Nice set of tutorials. Thanks for taking the time to do them.

  • I don't know what I did wrong. I didn't get the same numbers :'( someone HELP!

  • @death2link i guess because it's random, so you won't get the exact numbers with others CMIIW

  • @death2link lol its RANDOM so obviously you won't get the same numbers as him.

  • Bucky For PRESIDENT!

  • @turtlecat77 Bucky for supreme overlord of the universe.

  • 30 first tutorials first day ! Awwww Yeaah ;D

  • 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");

  • btw you only rolled 999 times lol

  • Comment removed

  • @Morcous16 that is because he started roll at 1 and didn't use roll <= 1000, so he would end up rolling 999 times

  • @bwoodlyrics i know...

  • help this man and donate him, if you dont want to spend out money click on the advertisement on his website: thenewboston(dot)com

  • 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.

  • really thanks for provinding this totorial......

  • LAAAAAWL

    listen at 0:16

  • 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 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.

  • Comment removed

  • took me a bit, but i fully understand the programming behind this. i makes sense to me :D

  • 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

    Type number of rolls:

    1000000000

    Face Frequency

    1 166663871

    2 166684546

    3 166676548

    4 166662082

    5 166659480

    6 166653472

  • 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\tFreq­uency"); for (int face = 0; face < freq.length; face++) { System.out.println(face + 1 + "\t" + freq[face]); } }

    }

  • why is the total of the numbers 999??

  • 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! :-)

  • This was probably the hardest video ive watched you made but when you explained in the end i finnaly understood

  • 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.

  • 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!

  • Hey, 160+158+181+168+181+151=999 and you told us dice rolled 1000 times not 999 times

  • @poyzz330 Remember the computer starts counting from zero

  • 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!

  • @mrhozer off by one errors should always be covered in beginner tutorials... they happen even to the pros

  • @mrhozer thank you so much that helped alot :)

  • wow...I did this without watching this and I did it a lot different.

  • Don't you wish your girlfriend was a freq[] like me?

  • 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.....

  • @NehiThompson copy and paste it here

  • 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.

  • It actually rolls the dice 999 times

  • @nevrahdavis You can change that by doing for(int roll =1;roll<=1000;roll++)

    Instead of for(int roll =1;roll<1000;roll++)

  • lol "that'll do pig, that'll do" i love that movie its called babe (tahts the pigs name and the movies name)

  • @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

  • int rnd = (int) ((Math.random()*6)+1);

  • 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.

  • Hey Bucky, thanks for the great tutorials. I just noticed that in this video you 'roll' the dice 999 times instead of 1000. ;-)

  • "name it freak or whatever..." hehe

  • 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. :)

  • yes i know that now and don't need any more answers please...

  • It will sum 999 times only, hehe, roll should be <= 1000

  • @ptchau2003 another alternative would be changing ++freq[1+rand.nextInt(6)] to freq[1+rand.nextInt(6)]++ i guess?

  • @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!

  • Comment removed

  • @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.

  • @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.

  • Man his child is gonna go through pottty training fast

  • I liked all your videos so far.

  • i didn't get the part ++freq to the end, any one can help??

  • @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.

  • could we write Random rand = new Random(rand>=1) or something like that in order to have all randoms except for 0?????

  • 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

  • oops i fugot... da loop strts frm 1... so da die rollz 999 tymz...

    add ur results n ul gt 999!!!...

  • @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)...

  • hey does anyone know how i would do this using math.random???

  • @MissShauna1234

    Math.random() gives a value between 0 and 1, for example it might give 0.3525155425.

  • 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 It only rolls 999 bec. the loop 'roll< 1000' - if we wanted 1000 the loop would be 'roll <=1000'.

  • @LadyDragon82105 It's rolling 998 times since it starts at 1, not 0.