@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.
@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.
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!
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
@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;-).
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
@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.
@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
Why is it that sometimes you put a variable inside the argument in the method? What's the difference between that and writing the variable inside the method body as we were doing in the first tutorials?
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
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.
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; } }
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing method body, or declare abstract at variablelength.average(variablelength.java:5) at variablelength.main(variablelength.java:3)
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.
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.
@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
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?
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? :
@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.
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!
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
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.
@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
Why did you declare second method, average, as static? I mean, what is the difference between public static int average() {..} and public int average() {..} ??
@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
@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.
@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.
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?
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!!!=)
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
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
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,76,2,31)){
Was this an answer to your question?
I asume you understand how an average is calculated? (sum/counter)
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.
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.
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!
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));
couldn't int...numbers just be int numbers[]? and then changed the for loop?
bogaming 1 day ago in playlist Java (Beginner) Programming Tutorials
I survived the arrays thank god
ROFLStudiosInc 2 days ago
Wait, Notch started Minecraft (Cave Game) May 29th 2009.... These tutorials are before that... Do you think....??
daymond12345 5 days ago
@daymond12345 could be
ROFLStudiosInc 2 days ago
@daymond12345 I don't know of this is a joke or not, but Notch started programming when he was a boy :)
XwatchmyvidsX 11 hours ago
i have a LOT of apple classes now...... yummmm :)
allendupras 1 week ago in playlist Java (Beginner) Programming Tutorials
@allendupras I name mine different kinds of fruit, I get kinda stuck, so I have to think of all different kinds of exotic fruits.
NinjaCatStudiosArt 1 week ago
O: USEFUL
ThisIsntBrandon 1 week ago
Yo dawg I herd u liek integer division.
Spydurz 2 weeks ago
Uggh!
I am just thinking to myself,
"Just think about the games you will be able to make after you waste your weekend"
Chillers1337 3 weeks ago in playlist Java (Beginner) Programming Tutorials
@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 3 weeks ago in playlist Java (Beginner) Programming Tutorials
@SuperGreenMiner whats your idea?
misterolichip 2 weeks ago in playlist Java (Beginner) Programming Tutorials
@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.
SuperGreenMiner 2 weeks ago
@SuperGreenMiner nice
misterolichip 2 weeks ago
@thenewboston This video is not downloadable...
kagamers 3 weeks ago in playlist Java (Beginner) Programming Tutorials
@kagamers You migh wanna try downloading it with "Youtube downloader" or something like that.
SuperGreenMiner 2 weeks ago
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!
kagamers 3 weeks ago in playlist Java (Beginner) Programming Tutorials
whats the significance of return
COD5252 3 weeks ago
"ellipse" is a shape. "..." = "ellipsis"
AlderDragon 3 weeks ago
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 1 month ago
@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.
AlderDragon 3 weeks ago
@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 3 weeks ago in playlist Java (Beginner) Programming Tutorials
@kyurempatel k, thx, i got it :D
drakion1989 1 week ago
@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;-).
MrYouMath 1 month ago
Comment removed
MrYouMath 1 month ago
Numbers is an array?
PrasinoXorton 1 month ago
Great, now I have to go look for the comment of some martian dude from WWII...
I hate this crap...
iambored2006 1 month ago 8
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 1 month ago
@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 1 month ago
@sikz26300 yeah i think i understand.Thanks!
yugesh88 1 month ago
@yugesh88 dont use double in second method use int
COD5252 3 weeks ago
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
MrManuhn 1 month ago in playlist Java Programming Tutorials
Apples, Tuna<< Due to these tutorials I can type those words in a split second XD
t4techy 1 month ago
@dudeperfectist So it basicly just gives the print statement the answer? If you didn't use return, it wouldn't print anything?
Arowzkill 2 months ago
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().
dudeperfectist 2 months ago
At 2:14 what does the command Return do?
Arowzkill 2 months ago
@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.
coyork15 2 months ago
I'm proud to be in the 10% who didn't fall out of bucky's great tutorial!
karolyipeti 2 months ago in playlist Java Programming Tutorials
... means 'Just Do It!'
Rypac15 2 months ago
@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 2 months ago 3
@USDAapprove Yes you REALLY did help thank you very much!
Justoneofthebrothers 2 months ago
This has been flagged as spam show
Why is it that sometimes you put a variable inside the argument in the method? What's the difference between that and writing the variable inside the method body as we were doing in the first tutorials?
Justoneofthebrothers 2 months ago
Comment removed
Justoneofthebrothers 2 months ago
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
akemko 2 months ago in playlist Java from thenewboston
3:23 the number went down because of the outlier 2.
agcummings11 2 months ago
ahhhhh im sooo confused
MrStropwen 2 months ago
Instead of using average as an int, wouldn't it be better to use it as a double?
opeAFromRSBot 2 months ago in playlist Java Programming Tutorials
@opeAFromRSBot omg haha thats EXACTLY what i thought
BrandonVIC96 2 months ago
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 2 months ago
@Shaldares its not some much as confusing its just ALOT too remember
MrStropwen 2 months ago
nvm i fixed my problem. i had the "return" command line within the "for" loop, and that caused the error.
lNUMPUN 2 months ago
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 2 months ago
@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.
mustafaalabaychi 2 months ago
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - missing method body, or declare abstract at variablelength.average(variablelength.java:5) at variablelength.main(variablelength.java:3)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)
varun513 2 months ago
I don't comment on every video, so to set the record straight: videos 1-35 get an A++. Now, on to the next ...!
33tracker 2 months ago
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.
ProxySpam 3 months ago
daymond12345 3 months ago
ackward....
SSHPCS2 3 months ago in playlist Java Programming Tutorials
45.75
44.625
eu2cy 3 months ago
Great vid, Hmmmm, because its averages we shouldn't be using "int" we should be using "double" :D
ismailzd 3 months ago
it just got real...
MrYourfavoriteguy 3 months ago in playlist Java Programming Tutorials
This is more addictive than 9gag
shammerHammer 3 months ago in playlist Java Programming Tutorials
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.
12me91 3 months ago
weird
mav89 3 months ago in playlist Java Programming Tutorials
is okay to have the [ ] after the String and not after the args?
elvisniperx 3 months ago in playlist More videos from thenewboston
@elvisniperx
yes.
kamul8 3 months ago in playlist Bucky's Java Tutorial
i have a question, what is the difference when your FOR LOOP doesn't have curly brackets? "{}".
elvisniperx 3 months ago
@elvisniperx when the for loop has only one line of code inside you can skip the {}, otherwise you need them.
Xeinnex1 3 months ago
@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
shammerHammer 3 months ago in playlist Java Programming Tutorials
Just as a reminder " int average " is a function not a method. anyway, everything else is perfect.
sinbadlook 3 months ago
@sinbadlook functions dont exist in java, they are called methods and they are the very same thing.
Xeinnex1 3 months ago
@DHerls Survival of the fittest? :D
potpie1010 3 months ago
The number of views keeps going down as the series progresses...
DHerls 3 months ago in playlist Java Programming Tutorials 60
@DHerls Those who get behind, are left behind...
NebulaOrbit 3 months ago in playlist Java Programming Tutorials
@DHerls now you know how many people have patience with java
TheAnthony123098 1 month ago in playlist More videos from thenewboston
@DHerls 13K view drop between this time and now.
kagamers 3 weeks ago in playlist Java (Beginner) Programming Tutorials
@DHerls It started around 700K
kagamers 3 weeks ago in playlist Java (Beginner) Programming Tutorials
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 4 months ago
AlephAriadiate 4 months ago
@ManofTheStraw The syntex is import java.util.Scanner;
knight11ind 3 months ago
I played with it alot.
RaqibulHayder 4 months ago
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 4 months ago
@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
:)
pudinda 4 months ago
When writing "int numbers[]" you have to write in main : int arrey[]={43,56,76,8,65,76,2,31}; System.out.println(average(arrey));
Mars1939Mars 5 months ago
@Mars1939Mars dude dont tell bucky to do anything when you cant even spell array correctly
iMitchay 5 months ago in playlist Java 31
@iMitchay actually, arrey is a name, so it doesnt have to be spelled array.
Xeinnex1 4 months ago
@Xeinnex1 yeah but why would you randomly name an array, "arrey" when you could just spell it normally
iMitchay 4 months ago
@iMitchay yeah but, why not?
Xeinnex1 4 months ago
@Xeinnex1 idk maybe because your retarded?
iMitchay 3 months ago
@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 3 months ago
@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 3 months ago
@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 3 months ago
@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 3 months ago
@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 3 months ago
@Xeinnex1 bleh.
iMitchay 3 months ago
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!
pcollins69 6 months ago
Scratch that.
canttouch552003 6 months ago
Comment removed
canttouch552003 6 months ago
What exactly is the difference between "int...numbers" and "int numbers[]" in this case?
MrMetallrider 6 months ago
@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
lalitmali 6 months ago in playlist Java Programming Tutorials
Comment removed
MrMetallrider 5 months ago
@lalitmali
ahh ok, i think i got i now :D thanks
MrMetallrider 5 months ago
why can't we just used arrays?
Tusharchutani 6 months ago
I like how he said "interesting average is only 44, hmm..."
its cause hes using int and not double. Happens to everyone
k24bfan 7 months ago
Wow. I'm surprised that's not a built in method/function
techerik14 7 months ago
Hey buck...why the average is static? please reply..
1programmerjava 7 months ago
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.
Deadly699 7 months ago
I am getting a headache!!!!!!! OUCH!!!
sciman001 8 months ago
So the Arguments are stored in an Array or what?
TheMasterMind555 8 months ago
@TheMasterMind555 *Facepalms self*
vansripper 8 months ago
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.
NehiThompson 8 months ago
whats the point in making 2 methods? i tried this using 1 method and it worked out perfectly!
Gam3r979 8 months ago
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/numbers.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 8 months ago
@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.
simba90s 8 months ago in playlist Java Programming Tutorials
@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.
MisterM2402 7 months ago
@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
MisterM2402 7 months ago
int/int that's why java shows only int number for example 44
shpenddbajgora 8 months ago
I tried changing ... to nike but it didn't work ):
ObeseCamelz 8 months ago
also, why do "public static int"...why not use "public static void"?
SargentSpecs 8 months ago
what is the point of adding the "return total/numbers.length"...what does that do?
SargentSpecs 8 months ago
@SargentSpecs it means it returns the value of total, divided by how many numbers are in the variable "numbers". a.k.a the length.
333OH333 8 months ago
So "numbers"s act here as an array?
Soniboy84 9 months ago
So the elipse basically creates...an ArrayList?
AdventKingBand 9 months ago
yeah thanks Bucky, " .... means just fucking do it ".
Dalwanaage 9 months ago
Comment removed
evelin6315 9 months ago
Why did you declare second method, average, as static? I mean, what is the difference between public static int average() {..} and public int average() {..} ??
thunderbird007 10 months ago
Free download? THANKS! I can watch it in school then :D Thanks :D
xXchidoriPOWERXx 10 months ago
@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 9 months ago
@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 :)
xXchidoriPOWERXx 9 months ago
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
TheLegitLogic 10 months ago
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 10 months ago
@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.
ytgodzilla 10 months ago
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 10 months ago
thanks for the tutorial
I benefit from it :)
u082910 11 months ago
what if i want to initialize a 2D vairable length array?
farazjanan1 11 months ago
Wow... This must be the first vid with 49,000 views and not a single dislike! :D
ryanjones56 11 months ago
Is the variable "numbers" a array? And if it is, why not be "number[ ]"?
meryqing 1 year ago
@meryqing Everything that contains more than 1 variable is an array.
kymykaly 1 year ago
You should've used double instead of int. (int) discards the decimal numbers.
abkmf 1 year ago
This has been flagged as spam show
Make your holiday free with a Latino women busizz4me.info
JACLYNRHONDA 1 year ago
how would you make it so that the user could type in the numbers he wants to average?
strawhatal 1 year ago
@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.
annasophia78 1 year ago
@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.
johnxxx9 1 year ago
so...many...Arrays!D:
0YellowSubmarine0 1 year ago
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?
ExhibitMan 1 year ago
Comment removed
ExhibitMan 1 year ago
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!!!=)
HIGHonLIFE1012 1 year ago
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 1 year ago
@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 1 year ago
@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**
freestylerstyler 1 year ago
I can't thank you enough for these videos.
mike3214545 1 year ago
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 1 year ago
@deshi2010desh hey there is no arrary set up in this programme so it would just be a normal int variable :)
jakiesnakie2 1 year ago
@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,76,2,31)){
Was this an answer to your question?
I asume you understand how an average is calculated? (sum/counter)
freestylerstyler 1 year ago
I think it would be easier to make an array and just use that
saaron62 1 year ago
@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.
freestylerstyler 1 year ago
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 1 year ago
@hummary use double!
Ajababy11 1 year ago
@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.
freestylerstyler 1 year ago
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 1 year ago
@heckyes1777 ..i agree, thats probably true, but i guess maybe because its easier to type int than doubles? XD hehehe
noTmiZ 1 year ago
while(x<sqrt(-2)){
System.out.println("Cliche " + x);
x=x+sqrt(3);
}
MrStereotypist 1 year ago
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.
Pelerouchi 1 year ago
We love youi never knew the ... funda
ajithcharles 1 year ago
if i wanted to average by user input how would i code that.
blaxarbush911 1 year ago
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
CodingMadeEasy 1 year ago
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!
Ps1ko85 1 year ago
What if i want to input the numbers from the keyboard? and i don't know how many I need to input
canuta16 1 year ago
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));
tuntuni1000 1 year ago
Why is your main method sometimes main(String[] args) and sometimes main(String args[])?
Hedgehogs4Me 1 year ago
Can u tell me the difference between
public static int average (int ...numbers)
public static int average (int numbers[])
shrikantnimbalkar 1 year ago