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

Link to this comment:

Share to:

All Comments (194)

Sign In or Sign Up now to post a comment!
  • I'm having difficulty understanding why one can't simply output ..."The sum of these numbers is " sum); Why all of the sudden, after appending the sum+=bucky[counter];, do you have to use +sum?

  • @Lennybird91 It does seem a bit odd to have to use a '+' before sum, but the fact remains that no matter what you pack on other than the initial "The sum of ____ is", will need one. So when you think about it, you still are adding -in a sense- to the rest of the println. Hope that helps... Somehow.

  • People always comment on how the views go down with each video. They aren't really going down any more but you can see from the comments that most people are watching for college or uni

  • @TheViolinCalamity look at the playlist. it gets down to like 45k people. and once it was in the 30s. but i have to agree with most people that stay. this guy is the best!

  • How do you sum the elements of a multidimensional array?

  • @RiaAndPreetiAntics You could use nested for loops, one dimension inside of the other.

  • best tutorials in youtube ever..really love you man

  • Thank you Bucky! If there wasn't your tutorials I would have never passed my Java-course! :)

  • ever seen a class of 120167 students?? :PP

  • Grammer Nazi Mode Activated:

    For multiples of something its "are" not "is" =(

  • @BigRunescapeBrain Counter-Grammar-Nazi-Activated­: It's "it's," not "its" when not discussing possession. ;-)

    As for what you pointed out, we fall into vague territory. Considering words such as "team" or "group" when in unison are both still singular, one might question whether the "sum" is behaving as singular. This of course depends, as I've neglected to remember the importance prepositional phrases ("of these numbers") when noting the plurality of the verb. Doh.

  • I missread summoning elements of arrays, and I was like =D

  • My class is more like "linkedlist. You make data and a pointer. Simple, right? Make one."

  • How do i save the variable as a matrix, and NOT a single integer?

  • u awesome,i am watching your sql as well. i am an amateur to programming but u make it so easy.

  • are you sick or tired or hungover on this vid? :))

  • Hey bucky, i really need help with this/ if anyone else knows.

    I am building a calculators using arrays and embedded ifs but i am trying to create an array to store functions like */-+ and i can't seem to work out the syntax for symbol (reply with answer or if you don't understand my meaning).

  • @caseyguitarist you can't store operaters into variables if that's what you're trying to do. i would just make a switch statement prompting each function (add, multiply, divide, etc...). idk if that's what your asking but my beginner brain tells me to do that.......

  • @FusionGTZ i have no fucking idea how i overlooked that

  • @SimKessy

    You shouldn't have gotten the same result, "sum+=bucky[counter]" would look for the number in the array counter is, so if counter was 0 the number in the array would be 21, etc.. Then it would add the array numbers. In "sum+=counter" it would just add the counter numbers, so you should get a number like 5 or 6 or something.

  • Thanks Bucky. Keep up the good work.

  • I wrote out line 7 like this "sum+=counter;" and came to the same result. I don't understand why its written as "sum+=bucky[counter]"

  • theze. lol

  • Why are arrays useful? Where will I put it on a Java game?

  • @fortawesomm I made a little text based blackjack game in c++ that I never finished. Now imagine all the cards and suits. You would have to make like 52 variables for each different card. Instead, you can just make 2 array.

    cards[] = {ace, two, three, four, five, six, sever, eight, nine, ten, jack, queen, king}

    suits[] = {spades, clubs, diamonds, hearts}

    Now you just go cards[4] + suits[3], to get the five of hearts. Although this is probably a bad example,it shows what arrays can be used for

  • @ilikemykebab pretty cool.

  • @fortawesomm when you start to make games, you will have to make a different variable for every pixel showed in the frame, in that case, if you have like 800 by 640 pixels, that would suck to make that many variables. instead you will use arrays. but you will actually be making multi dimensional arrays. which you will learn later if you keep watching these videos.

  • Thanks for the help guys!

  • Comment removed

  • Comment removed

  • Why am I getting a "counter cannot be resolved to a variable" error on line 11? I copied the code exactly and re-did it 3 times.

  • @forexdragon Instead of using counter i did this "for (int i=0;i<age.length;i++){ sum += age[i];

     }"

  • @forexdragon This sounds like when you initilize counter at for( int counter = 0; you are missing int.

  • @forexdragon You have mis-typed your code, here is what it should look like:

    for (int counter =0; counter<bucky.length; counter++){ total+=bucky[counter]; } 

  • LOL i did totally random numbers and i got 146. 1 away

  • AWESOME...ur much better than my stupid teacher xD

  • Which Variable could I use if I want text strings in the array?

  • what does += do?

  • @ChrisTheBest1992 it adds on to whatever was previously saved to that value. say you initialised an integer sum = 2; if you were to do something lile 'sum += sum + 1' and output sum you would get 5. This is because it acts as 5 + (2+1). Hope that helps.

  • @ChrisTheBest1992 It's a shorthand for writing the following.

    Num1 = num1 + num2

    That's the same as:

    Num1 += num2

  • System.out.printf("The sum of theze numberz iz %d .", sum);

    %d is the identifier for numbers. sum replaced %d when printed out.

  • when bucky says, "'sup guys this is bucky" he sounds like one of the goth kids from south park. lol

  • click ads to donate to bucky!

  • How do i get a period (".") right behind the number (147) in the output?

    it would work with

    System.out.print("The sum of these numbers is " +sum);

    System.out.print(".");

    but there has to be a more elegant way, right?

  • @TheCarmacon System.out.print("The sum of these numbers is " +sum+".");

  • @JKTCGMV13 thanks a lot, mate :)

  • what does += do?

  • @WorldBuildings

    "sum+= bucky" is the same like "sum= sum + bucky" ;D

  • @WorldBuildings it adds the ammount u choose, for example x +=5 <--- this will add 5 to the current value of X.

    you can also do -= which will subtract that ammount

  • write syso and press CTRL + SPACE to get System.out.println();

  • @theXminecrafter i love u

  • starting to get confusing..

  • I subscribed.

  • IM NOT SUBSCRIBING BUT THANK YOU

  • 2 days ago a was a 22 years old university student that was studying computer engineering and tried to cheat my Java exams. After im done with these tutorials my teacher is going to cheat so she can give me less points in the upcoming exams.

  • THESE , not THEZE

  • @RASHTG someone has no sense of humor

  • @RazorSRaider HAHA. I figured it out later. 

  • I didnt completely get the video b4 this one until i watch this video

  • THX MAN!!!! :D Finnaly i finníshed this :) Added some good stuffs :) Now the program will typ out all the Numbers like this "Numbers: 21,16,86,21,3"

    And on the next line it will print out the sum of those numbers like this "The sum of these number is 147" And on the third line it will tell the avagre of them :) Like this "The avagre of those numbers is 29" :D I have been watching your videos all day :) So i have been total watched 29 of your videos now :) And i'm learning alll the time!

  • theze ftw

  • For anyone who wants it as a while loop int sum=0;

    int counter=0; while(counter<bucky.length) { sum+=bucky[counter];

    counter++;

    }

  • OH MY GOSH!!! I WAS JUST TYPING RANDOM NUMBERS IN AND I ACTUALLY TYPED THE EXACT SAME NUMBERS AND SAME AMOUNT OF NUMBERS!

  • @anthropamorphic OMGGGGGGGGGGGGGGGGGGGGGGGGGGGG­GGGGG. lol

  • In my programming class, the teacher will try to teach a lesson, i wont get it, come home, watch your video, and understand it completely <3

  • @JankMonkey lol same with me. just spent hours trying to figure something out. found my answer here... THANKS BUCKY. YOU ROCK!!!

  • @JankMonkey The university should just fire the teacher and put you in a room and turn on these tutorials. xD

  • u r the best--->bucky

  • it gives me This message: "Exception in thread "main" java.lang.ArrayIndexOutOfBound­sException: 5

    at apples.main(apples.java:11)

    Help please!!

  • @RaymundoGabriel, check if you have proper capitalization and use ; at the end of everything.

  • @HeteroProductions Thanks

    it help

    

  • @RaymundoGabriel

    No problem :)

  • @RaymundoGabriel Looks like you are doing counter<=bucky.length instead of counter<bucky.length

  • @Blinxkitty Thank you , Hello Form Mexico City (i live here)

  • You are so good that my teacher just shows your tutorials to my class as her lesson.

  • @DexManley0 So did my teacher also. All the members of my class is watching bucky.

  • @DexManley0 lol :D

  • @DexManley0 Lucky you... I wish there were java lessons in seventh grade............ xD

  • @sporreking That would be awesome! I wonder why have the people that start programming are around my age(12). Is it just for games? simply because of minecraft? haha

  • @DexManley0 Stop gloating :(

  • @DexManley0 u serious!?

  • @DexManley0 yea my teacher did the same thing which then made me not want to come to class... bad teacher but BUCKy is the best

  • public class apples{ public static void main(String[] args) { int kyte[]={32,45,56,78,90}; int sum=0; for(int counter=0;counter<kyte.length;­counter++);{ sum+=kyte[counter]; } System.out.println("the sum of these numbers is 147" +sum); }

    }

    IT KEEPS SAYING THE COUNTER IN THE SQUARE BRACKETS IS AN ERROR :(

  • @kyte95 because there's a semicolon after the for loop condition ..

    public class apples{ public static void main(String[] args) { int kyte[]={32,45,56,78,90}; int sum=0; for(int counter=0;counter<kyte.length;­counter++){ sum+=kyte[counter]; } System.out.println("the sum of these numbers is " +sum); }

    }

  • @kyte95

    take the ; out after your for loop before the { sum+=kyte[counter];}

  • @kyte95 Have you found the answer on this Kyte?

  • Who's got 6 bullets?

  • ..and in case you want to know how many numbers you have in your array:

    public class LearnJava{ public static void main(String args[]){ int num[] = {10, 20, 30, 40, 50}; int counter=0; while(counter<num.length){ counter++; } System.out.printf("The array contains " + counter + " numbers!"); }

    }

  • thank you

  • i decided to try and get a average and just did +sum / number of objects and changed int to double. Worked well!

  • System.out.println(sum/bucky.l­ength);

    For the average

  • Comment removed

  • theze tutorials are good.

  • If your arrays are ages and you want to find the average age, use this

    System.out.println("The average age is " + sum/bucky.length);

    Works no matter how many arrays you got.

  • Comment removed

  • Yo dawg, I heard you like arrays, so we put an array in yo array so you can initialize while you initialize!

  • They are called multidimensional arrays.

  • A tip for this sort of thing.

    If you think there's any chance you could be summing a large array, or one with large int values, you may want to make your sum variable to be of type long to prevent overflow. A long is the same is an int but can store a much bigger range of values.

  • You are very good with the Java language. Not so much the English language :P

  • @ravensrock86 lol

  • ack... I find too many praises here... :)

  • @peeyam , actually if you do as bucky does your array will be like bucky[0] bucky [1] ... bucky[4] , but if you add "=" , it will get one more value , but since array content only five values , bucky[5] doesn't exist.And you are out of 0,1,...,4 index.

  • shouldn't line 7 have "counter<=bucky.length"??? I know it works, but when it gets to bucky[5].. it shouldn't add the "3" to it... and if I put the "=" sign in.. I get an error "Exception in thread "main" java.lang.ArrayIndexoutOfBound­sException: 5 at apples.main(apples.java.:8)

  • im geetin this error message Exception in thread "main" java.lang.Error: Unresolved compilation problem: counter cannot be resolved to a variable at apples.main(apples.java:7)

  • Your tutorials are MY PRECIOUS!

  • sum+=bucky[counter];

    Does java temporally store the total sum in [counter]?

    Thanks in advance.

    

  • Comment removed

  • hey bucky what if all numbers that i want to add is in a variable? and what if the array length is based on what the user will input in another variable? hope u get wat i want to do! pls help

  • BTW gaiz, if you add a sum=sum/bucky.length; and then output it on the screen you can get the array average, i think, unless java divides it by 2 or something

  • omg genius!

  • Hmm in php you can just do array_sum($array) and it will add the whole thing without doing a loop... wonder if java has an equivalent function...

  • @after731 If not, you could always create your own class to do it much faster.

  • @after731 Google may have you answer

  • @theend1245: You can't have array within array, but you can create multiple dimension array...Two dimensional arrays (matrix) is defined by two "[ ] [ ]", so it has two indexes, one for row and second for column...

  • you are great man

    you are very very very claver thank you very match

    oday zahde

    palestine - hebron

  • how do you make an array of words, instead of numbers?

  • @4thKyuubi

    String

  • @4thKyuubi <_< Use The String Variable Instead of Int

  • Comment removed

  • my java teacher sux, i always come here if i dont understand something;p

  • @283518 Obviously not or else he would not have gotten hired, why blame the teacher because "you don't get it"

  • @MrMelonBread if the class average is 56% thats not a good teacher, never helps anyone, never stays after class, never answers questions, never does examples, at the risk of sounding redundant my teacher SUCKED!;p

  • @MrMelonBread btw the first part of ur comment to me doesnt make sense,lol jst thought ud like to know;p

  • @283518 What I meant was that he must have good enough to get the jopb, and also note that just cause your class average is low does not mean it is the teacher fault, hell my Programming class' average was in the 60s yet we had a great teacher.

  • @MrMelonBread lol im not sayin all teachers are bad, my java prof this semester was the shizzle as the kids say lol, but ther are good teachers and bad teachers and im tellin u, my old teacher was horrible, how is anyone supposed to get good marks if a teacher marks on how he feels, one day happy, next day pissed, there are such things as bad teacher is wat im sayin

  • @MrMelonBread That means your class was retarded then.

  • @mayhempk1 I agreed, that was my point. It is more about the student than it is the teacher

  • i thought he was gonna say "theze nuts".

  • what about this?

    double var;

    var=6*Math.random();

    var=Math.floor(var++);

    System.out.println(var);

    btw Math.random() gives a number from 0 to 0.999999999...

  • GUI question... I have a textfield, and an 'enter' button, I need the value of the textfield to be entered into an array[ ].. each time the button is pressed i need the new value stored in the next [index] ... I can't figure out how to do this.. can anyone Help??

    BTW... your tuts are awesome!

  • THANKS FOR THE VID!!!!

  • I didn't know you took requests. I'll take a Grey Goose Vodka Martini with one olive.

  • hi,

    great video by the way :)... just a quick question, why do you need to increment he counter variable?

    Thanks!

  • @MrJSmithify if you dont you would be stuck in the for loop forever :O

  • omg sry for spam browser was bugged so i clicked like milion of times on "post" sry :@ :S

  • @Tijosav dude, just remove the equal sign from the counter<=Milan.length and run it. i encounter that problem to right now

  • Comment removed

  • Comment removed

  • Comment removed

  • Comment removed

  • Comment removed

  • Of course, programmers do so all the time.

    First, create the array you want (for example, int[] bucky). Now add another pair of square brackets (int[][] bucky).

    There you go.

  • yes, it would be a two dimentional array then, if you add more to that, it would be three dimentional, etc.

  • Sure, but what would be the point? It would be like having a table inside the cell of a bigger table

  • @theend1245

    what you want, is a Multidimensional Array.

    the tutorial 33 is about that

  • its possible with linked lists

  • @theend1245 i think it can be done .. but i never did it before

  • @BadMadB0y of course it can be done, its called a matrix or 2 dimensional array, like int myArray[3][3]={

    1,2,3,

    4,5,6,

    7,8,9};

    myArray[1][2] = 6

  • @theend1245

    2dimensional arrays

  • @theend1245 check vectors they might do the trick x)

  • @theend1245 You know, if you used Google you would get you answer faster

  • @theend1245 you can write int arraynam[20][20]. Which would create 20x20 array. which means each array has an array of 20.

    So you could go: arrayname[0][7] = 2; arrayname[0][4] = 6 arrayname[2][19] = -2;

    and so on, you could make even more "dimensions" like.

    Like this: int arrayname[20][20][20];

    but be careful the memory you are using expands fast.

    an int arrayname[20][20][20]; would have to use 32000 bytes of memory.

  • @theend1245 You can have a multidimensional array.

  • @theend1245

    yeah they're called multidimensional arrays and they're defined as " var array [ ][ ]" (var can be any type you want, even a class ). Basically the same syntax as C and C++

  • @theend1245 See tutorial 33 - Multidimensional Arrays. Also, Rorschackh's comment.

  • @theend1245

    yes u can create arrays in arrays.

    just make more brackets like that [ ] [ ]

    It is like having drawers in drawers ;-)

  • @theend1245 yup it's possible.. it's called a 2-D array..