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

Link to this comment:

Share to:

All Comments (225)

Sign In or Sign Up now to post a comment!
  • couldn't int...numbers just be int numbers[]? and then changed the for loop?

  • I survived the arrays thank god

  • Wait, Notch started Minecraft (Cave Game) May 29th 2009.... These tutorials are before that... Do you think....??

  • @daymond12345 could be

  • @daymond12345 I don't know of this is a joke or not, but Notch started programming when he was a boy :)

  • i have a LOT of apple classes now...... yummmm :)

  • @allendupras I name mine different kinds of fruit, I get kinda stuck, so I have to think of all different kinds of exotic fruits.

  • O: USEFUL

  • Yo dawg I herd u liek integer division.

  • Uggh!

    I am just thinking to myself,

    "Just think about the games you will be able to make after you waste your weekend"

  • @Chillers1337 I have thought of a really cool game. so i just think about how i'm gonna do that. of course it  will take a very long time. but i can deal with that.

  • @SuperGreenMiner whats your idea?

    

  • @misterolichip a side view game where you command a squad. and thats all i am going to say about it. rest will come on my other channel (fewcode) when i get better at coding. and can start. so far i have designed 2 levels.

  • @thenewboston This video is not downloadable...

  • @kagamers You migh wanna try downloading it with "Youtube downloader" or something like that.

  • I don't understand this: why is it in our main method we establish the variables outside the params after the method title (in this case, main), but in other methods, we must establish the variables in the params after the method title?

    Someone PLEASE help me with this? I'm so confused about this and I have been for a while!

  • whats the significance of return

  • "ellipse" is a shape. "..." = "ellipsis"

  • Srry, i forgot this but could someone tell in the following code line... "for(intx:numbers)" what is the meaning of " : " or diference betwen " = " and " : "?.

  • @drakion1989 that cycles through each index of numbers. The variable x is an int because numbers is an array of ints. So inside the loop, the first time, x = numbers[0]. Then x = numbers[1] ... etc. x is changing each time, taking on the value of each consecutive value in the numbers array.

  • @drakion1989 = would mean int x = numbers the : is an for the advanced for loop (see the turorial its like 31-34 somet) the advanced for loops just means that the int x = the numbers that loop is going thorugh at the moment so at the second time it loops it would equal the second number hope this helps

  • @kyurempatel k, thx, i got it :D

  • @Bucky: Hi bro, your programm doesn't give back the avarage. The programm is giving the integer part of the mean. You should use double everywhere you have int;-).

  • Comment removed

  • Numbers is an array?

  • Great, now I have to go look for the comment of some martian dude from WWII...

    I hate this crap...

  • Can somebody pls tell me why we need to make the average() "static" ?

    It gives errors if we don't : Cannot make a static reference to the non-static method average(double[]) from the type apples

  • @yugesh88 if you don't make it static you will have to call the object of the class. we haven't created any objects in this class. does that help?

  • @sikz26300 yeah i think i understand.Thanks!

  • @yugesh88 dont use double in second method use int

  • hi bucky, i think its better to have the types of numbers and total,and x in double type,instead of int as you may loss info as the average calculated may be decimal numbers :D

  • Apples, Tuna<< Due to these tutorials I can type those words in a split second XD

  • @dudeperfectist So it basicly just gives the print statement the answer? If you didn't use return, it wouldn't print anything?

  • Arowzkill

    if there wouldn't be return, when you call average method, it won't write anything. It shows, what should the human see when he calls average().

  • At 2:14 what does the command Return do?

  • @Arowzkill It lets you set something equal to to what's in your method. So if I have a method with return x; I can then access x from outside of that method.

  • I'm proud to be in the 10% who didn't fall out of bucky's great tutorial!

  • ... means 'Just Do It!'

  • @Justoneofthebrothers because that's bad programming practice what we do is set the variable in one method and then send it to the other methods through the parameters and the reason for that is so that we can send that array or other info to multiple methods hope that helped

  • @USDAapprove Yes you REALLY did help thank you very much!

  • Comment removed

  • this is one of the cool thing i learned new, for the people who are telling syntax mistakes. f** u all, try to motivate what he is trying to teach dumps

  • 3:23 the number went down because of the outlier 2.

  • ahhhhh im sooo confused

  • Instead of using average as an int, wouldn't it be better to use it as a double?

  • @opeAFromRSBot omg haha thats EXACTLY what i thought

  • I don't understand how so many people drop out of these tutorials. Bucky makes it so fucking simple. It's so much easier to understand than any programming textbook I've ever read.

  • @Shaldares its not some much as confusing its just ALOT too remember

  • nvm i fixed my problem. i had the "return" command line within the "for" loop, and that caused the error.

  • I replaced the word "int" everywhere with the word "double", and I'm getting this error:

    "This method must return a result of type double."

    Here is my code:

    class Jtut35{ public static void main(String args[]){ System.out.println(average(43,­56,76,8)); } public static double average(double...numbers){ double total = 0; for(double x: numbers){ total += x; return total / numbers.length; } }

    }

  • @lNUMPUN You have to delete "{" in the for loop. I mean, instead of writing: for(double x: numbers){ total += x; return total / numbers.length; }

    you have to write : for(double x: numbers) total += x; return total / numbers.length;

    try it . It should work.

  • Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing method body, or declare abstract at variablelength.average(variabl­elength.java:5) at variablelength.main(variablele­ngth.java:3)

    Java Result: 1

    BUILD SUCCESSFUL (total time: 2 seconds)

  • I don't comment on every video, so to set the record straight: videos 1-35 get an A++. Now, on to the next ...!

  • ya...happends in school too. I get 91%, 83%, 23% and 73% and when I do the average it's like 60%....LOL I wish the low values counted for like....idk, I wish they just didn't count at all.

  • I made Bucky's calculater easier! import java.util.Scanner; public class apples { public static void main(String[] args) { Scanner scan = new Scanner(System.in); double fnum, snum; System.out.println("First: "); fnum = scan.nextDouble(); System.out.println("Second: "); snum = scan.nextDouble(); System.out.println(fnum + snum); } }
  • ackward....

  • 45.75

    44.625

  • Great vid, Hmmmm, because its averages we shouldn't be using "int" we should be using "double" :D

  • it just got real...

  • This is more addictive than 9gag

  • This dude is teaching more in the few weeks ive watched him than one semester at college. Now if I could just figure out where to dl them it would be perfect.

  • weird

  • is okay to have the [ ] after the String and not after the args?

  • @elvisniperx

    yes.

  • i have a question, what is the difference when your FOR LOOP doesn't have curly brackets? "{}".

  • @elvisniperx when the for loop has only one line of code inside you can skip the {}, otherwise you need them.

  • @elvisniperx this is just a way to save some typing and you can do it with "while" "for" "do..while" "if" "else" and so on: whenever you have just ONE command (that usually would be in the curly brackets, you can leave them out. for example

    if(i<12)

    System.out.println("it is less than 12")

    but _NOT_

    if (i<12)

    i++;

    System.out.println(i);

    int this 2nd case you NEED the curly brackets!

    So, if you want to be right everytime,always do them. if you want to save time, you can sometimes leave them out

  • Just as a reminder " int average " is a function not a method. anyway, everything else is perfect.

  • @sinbadlook functions dont exist in java, they are called methods and they are the very same thing.

  • @DHerls  Survival of the fittest? :D

  • The number of views keeps going down as the series progresses...

  • @DHerls Those who get behind, are left behind...

  • @DHerls now you know how many people have patience with java

  • @DHerls 13K view drop between this time and now.

  • @DHerls It started around 700K

  • hello, i have a trouble that is make me crazy, cause i want to know how i can enter the numbers to the variable with an scanner what is the syntax for that, if someone can help me please

  • @ManofTheStraw Hi guy, If I well understood you question, let me guy explain to you how it works: first you you import the Scanner before writing the class: import java.util.Scanner; second, you create a scanner object in the main method: Scanner scan = new Scanner(System.in); third, you declare an integer variable: int var; fourth, you put the number you get with the scanner into the variable: var = scan.nextInt(); Did I answer you correctly?
  • @ManofTheStraw The syntex is import java.util.Scanner;

  • I played with it alot.

  • I have a question... instead of making an array with numbers i put in the brackets, then sending it with the length argument ...numbers, couldnt i just send the array like this? :

    public static int average(int []numbers)

    int total = 0;

    for(int x: numbers)

    {

    total += x;

    }

    System.out.println(total);

  • @pudinda

    1.instead of printing total it should print total / Array.length

    2. i forgot to put it in a method, but i think it should still work

    :)

  • When writing "int numbers[]" you have to write in main : int arrey[]={43,56,76,8,65,76,2,31­}; System.out.println(average(arr­ey));

  • @Mars1939Mars dude dont tell bucky to do anything when you cant even spell array correctly

  • @iMitchay actually, arrey is a name, so it doesnt have to be spelled array.

  • @Xeinnex1 yeah but why would you randomly name an array, "arrey" when you could just spell it normally

  • @iMitchay yeah but, why not?

  • @Xeinnex1 idk maybe because your retarded?

  • @iMitchay no, the reason is because you can, and u can name them however you want, so its pointless to say he cant spell array correctly, but whatever :), its not like i care about your brain capabilities

  • @Xeinnex1 yeah i'm gonna guess he's just stupid and its not just because he could, its because he couldn't. besides why wouldn't you name it like "array1" or something like that?

  • @iMitchay well, you can guess whatever u want :), but despite all that conversation about that guy, i want to tell you that naming an array "array1" is fine for simple programs like the ones in these tutorials, but when you have a huge program with 50 classes interacting and like 20000 lines of code, and after 6 months you want to fix some random bug, you probably wont remember what "array1" is, so unless you want to spend time on comments, you should make your names as clear as possible. :)

  • @Xeinnex1 obviously i meant name it "array1" because the array in this particular program serves no real purpose other than being an example, and you would name something that does have a purpose something to do with what it does. why did you even reply to my first comment anyway, idiot.

  • @iMitchay i replied to let you know how pointless it was, and stupid too, just assuming he doesnt know how to spell array because he decided to name a variable arrey, please dont reply to me anymore, its kind of annoying seeing your replies there.

  • @Xeinnex1 bleh.

  • I'm slightly confused, does that mean that int...numbers is an array? Because it's being accessed the same as you would access an array, eg numbers.length, and the enhanced for loop, if it's not, how are the numbers being stored? Btw Bucky these tutorials really are brilliant!

  • Scratch that.

  • Comment removed

  • What exactly is the difference between "int...numbers" and "int numbers[]" in this case?

  • @MrMetallrider

    nice question, i tried it and this is the error it gives i got 'The method average(int[]) in the type main is not applicable for the arguments (int, int, int, int, int, int, int, int, int, int)'

    if u pass a dynamic array as well as a single variable together in the arguments, then the compiler won't know how many arguments to accept in the array and how many to pass ahead for other arguments

  • Comment removed

  • @lalitmali

    ahh ok, i think i got i now :D thanks

  • why can't we just used arrays?

  • I like how he said "interesting average is only 44, hmm..."

    its cause hes using int and not double. Happens to everyone

  • Wow. I'm surprised that's not a built in method/function

  • Hey buck...why the average is static? please reply..

  • is there a way to send a list of numbers to a parameter, thats an array?

    I mean so you wouldnt have to delcare an array, fill it with values and then send it.

  • I am getting a headache!!!!!!! OUCH!!!

  • So the Arguments are stored in an Array or what?

  • @TheMasterMind555 *Facepalms self*

  • I think we need a tutorial on exactly WHAT arguments are and their function. Up til now obviously we've been using them, but I'm not completely clear on their breadth of functions.

  • whats the point in making 2 methods? i tried this using 1 method and it worked out perfectly!

  • class apples{ public static void main(String []args){ average(1,2,3,4,5); } public static void average(int...numbers){ int total=0; for(int x:numbers){ total+= x; }System.out.println(total/numb­ers.length); }

    }

    Why do we use return type? i dont understand in which situations to use or not to use return type! can some1 explain me xD

  • @BDCRap ok, lets say you have : System.out.println(average(10,­20));

    The return type kinda indicates what is the value of average(10,20). In this case, the value of average(10,20) is 15

    Therefore, with System.out.println(average(10,­20)); the average(10,20) will be replaced with its return value, which is 15.

  • @BDCRap "Return" isn't a type, it's a "keyword" (words used by a programming language that you can't use as variable names [or look up the term for a better explanation than mine haha]).

    "Return" tells the program what value it's supposed to give for the method "average(1,2,3,4,5)" - "total/numbers.length" is the value of the average of all the numbers and is the value that gets "returned", to be used in "main".

    Think of the Math.sqrt(x) method from before - it "returns" the square root of x.

  • @BDCRap Also note that the "int" of "public static int" tells the "average" method what TYPE of data to return.

    The reason it is "public static VOID" for the "main" method is because it doesn't need to return anything, so the return type is "void"... I am guessing :P

  • int/int that's why java shows only int number for example 44

  • I tried changing ... to nike but it didn't work ):

  • also, why do "public static int"...why not use "public static void"?

  • what is the point of adding the "return total/numbers.length"...what does that do?

  • @SargentSpecs it means it returns the value of total, divided by how many numbers are in the variable "numbers". a.k.a the length.

  • So "numbers"s act here as an array? 

  • So the elipse basically creates...an ArrayList?

  • yeah thanks Bucky, " .... means just fucking do it ".

  • Comment removed

  • Why did you declare second method, average, as static? I mean, what is the difference between public static int average() {..} and public int average() {..} ??

  • Free download? THANKS! I can watch it in school then :D Thanks :D

  • @xXchidoriPOWERXx if you're using mozilla, download "download helper" plug-in, and then you can download youtube and other videos for FREE :) If you don't use firefox....use it! :p

  • @hdanijel Thanks Man! Hahaha, but since utube wont take it down.. i dun feel like infringing the teacher's IP rights :) Just view it here, thanks again though :)

  • Lol, "dot dot dot means just do it, and i'm not gonna tell you how many numbers."

    What abrasive punctuation that is. To add on, i want to say that your tutorials are amazing. After watching the 20th video, i had the idea to write a program to factor equations. While I have not been fully successful, I found that whenever i looked up how to do something I had the right foundation to learn from because you don't just teach how, you teach why. That's what sets you apart from all the other tutorials

  • suppose the arguments i want to pass are coming from a user input.

    eg.

    the user states the number of items he wishes to enter

    he enters all

    when it finishes, then all this number are passed as arguments?

  • @geekyalo I tried that. I think I it failed with a variable length statement. I think I solved the problem by building a class that let the user populate everything individually.

  • suppose the arguments i want to pass are coming from a user input.

    eg.

    the user states the number of items he wishes to enter

    he enters all

    when it finishes, then all this number are passed as arguments?

  • thanks for the tutorial

    I benefit from it :)

  • what if i want to initialize a 2D vairable length array?

  • Wow... This must be the first vid with 49,000 views and not a single dislike! :D

  • Is the variable "numbers" a array? And if it is, why not be "number[ ]"?

  • @meryqing Everything that contains more than 1 variable is an array.

  • You should've used double instead of int. (int) discards the decimal numbers.

  • how would you make it so that the user could type in the numbers he wants to average?

  • @strawhatal You would need to use the Scanner (java.util.Scanner library) utility to get input from the keyboard. He explained the scanner utility in one of his first tutorials.

  • @strawhatal Use scanner. declare an array, ask the user to input whatever numbers he wants to and store those in the array, pass on the array to the function.

  • so...many...Arrays!D:

  • I didn't understand the motive, but do you mean that the list of numbers on system.in is taking one of these numbers and stores them in 'numbers' & then just calculates the average from them automatically?

  • Comment removed

  • haha Bucky, you explain things so clear. If you had a class going on at a college I would definitely attend every day, especially since you make it fun. Right now my first semester is about to end but I still don't get most of the stuff my professor is TRYING to teach. but after watching your videos there are some things that cleared up. but THANKS for your videos. keep it up!!!=)

  • Bucky, i've noticed you use easyeclipse.

    But I kept wondering why you take the effort to type {} after every method:

    for example: static void main {}

    If you just type static void main{ "press enter"

    you get the following automatically: static void main{ | <--cursor }

    I actually tought YOU something!!! :D

  • @freestylerstyler

    hehe Very funny, If you are teaching him then its better that you should upload some feasible video tutorials,,,, hehe,, but its good to shere the knowledge.... Enjoy the videos ,,,, Intresting

  • @Ayazmpengr

    Hehe, you're probably right.

    But it seems I am only in a learning stage so I really can't compete with Bucky.

    **crawls in a corner and cries**

  • I can't thank you enough for these videos.

  • very nice tutorial but i didn't understand one thing and thats the variable number we put in the method parameter is it array now coz you r using for loop for variable number or is it just regular variable pls tell me i m confused thnx

  • @deshi2010desh hey there is no arrary set up in this programme so it would just be a normal int variable :)

  • @deshi2010desh

    It's just a variable that stands for all the numbers you insert in the method average in the main function.

    example:

    public static void main(String[] args) { System.out.println(average(43,­56,76,8,65,76,2,31)); } \\ in the method, this would be public static int average(int...(43,56,76,8,65,7­6,2,31)){

    Was this an answer to your question?

    I asume you understand how an average is calculated? (sum/counter)

  • I think it would be easier to make an array and just use that

  • @saaron62

    Not exactly, an array is stored in the memory. So imagine writing a large java program for a company, this would be a plugin for a huge program. To keep it clear for devlopers, you'd best avoid using a lot of arrays to prevent confusion.

    My conclusion, why use an array if it's a plugin that always resets itself when executed.

  • Hey Bucky I've been wondering if you can average decimal numbers such as 23.4, 45.6, if its possible can you please tell me how?

  • @hummary use double!

  • @hummary

    You should use a type double. But make sure that all your variables that will eventually store the result are of the type double.

    Because, if you store 2.4 in an int, this will become 2, meaning you've lost 0.4.

  • if you wanted to be more accurate, wouldnt you convert the int's to doubles, then return a double? otherwise your "average" that it returns might be off by somewhere less than one, taking into account the decimals that integer truncates.

    just wondering :] love the tutorials!

  • @heckyes1777 ..i agree, thats probably true, but i guess maybe because its easier to type int than doubles? XD hehehe

  • while(x<sqrt(-2)){

    System.out.println("Cliche " + x);

    x=x+sqrt(3);

    }

  • Great tutorial! Keep up the good work! Changing the average method to:

    static double average(int...numbers) {  double total = 0; for (int x:numbers) total+=x; return total/numbers.length; }

    would give you correct averages.

  • We love youi never knew the ... funda

  • if i wanted to average by user input how would i code that.

  • Man you're good at explaining! You keep me entertained an ready to code! I try making C++ tutorials but they're not nearly as good as your tutorials.

    You're very talented :D

  • Hey Bucky! I want to let you know you the best at explaining these for me. My d**b Java professor cannot explain for crap. All he says is do the assignments and look out for new technologies. Your tutorials are great and you should somehow get paid for this. I think everyone would agree to that. Keep up the good job. You are helping lots of folks here. God Bless!

  • What if i want to input the numbers from the keyboard? and i don't know how many I need to input

  • Oh, and also for (int numbers[]) you would need an existing array like int bucky[] = {1, 2 ,3}; and for (int...numbers) you can just call you method, average, and for the argument type in the numbers you want to get the average of and save them to a variable and print them or you could use System.out.print(average(1, 2, 3, 4));

  • Why is your main method sometimes main(String[] args) and sometimes main(String args[])?

  • Can u tell me the difference between

    public static int average (int ...numbers)

    public static int average (int numbers[])