[font="arial, verdana, tahoma, sans-serif"]
int[] arrayThree = new int[20];
int total = 3;
for (int i = 0; i < 20; i++)
total = total*arrayThree;
TextIO.putln(total);
Please don't mind the fact that I haven't commented any of the code, but it's a very small program that I'm sure should be much simpler than I'm making it out to be. Basically, what I'm trying to do is create an array of multiples of three so I can add everything within the array after everything is said and done. I'm a straight up newbie here and have been reading as much as I can, but I learn most by applying concepts I read.
I imagine most of you are familiar with Project Euler and for those who are, I'm trying to find the solution to Problem 1. I DO NOT WANT THE ANSWER. Just point me in the right direction, if you could. =) Thanks, in advance.
[/font][font="arial, verdana, tahoma, sans-serif"]"int[] arrayThree" declares an array of integers named arrayThree[/font]
[font="arial, verdana, tahoma, sans-serif"] [/font]
[font="arial, verdana, tahoma, sans-serif"] [/font][font="arial, verdana, tahoma, sans-serif"]"new int[20]" allocates a space in memory for an array, made up of 20 elements, with each element being an integer[/font]
[font="arial, verdana, tahoma, sans-serif"] [/font]
[font="arial, verdana, tahoma, sans-serif"] [/font][font="arial, verdana, tahoma, sans-serif"]"arrayThree
" here you are trying to access the i[sup]th[/sup] element of arrayThree. [/font]
[font="arial, verdana, tahoma, sans-serif"] [/font]
[font="arial, verdana, tahoma, sans-serif"]the problem is that element i of arrayThree contains... well, we don't know what it contains! you never assigned an integer to that element, so doing any calculations on it will cause an error when you try to run your program. [/font]this video is a good explanation, helped me learn the concept of arrays and visualise it! http://www.youtube.c...&feature=relmfu
[font="arial, verdana, tahoma, sans-serif"] [/font]
[font="arial, verdana, tahoma, sans-serif"]also you should become familiar with the modulus (%) operator, it gives you the remainder left after dividing a number. it should help you solve that problem rather easily! project euler is awesome![/font]
[font="arial, verdana, tahoma, sans-serif"] [/font]
[font="arial, verdana, tahoma, sans-serif"] [/font][font="arial, verdana, tahoma, sans-serif"]e.g.[/font]
[font="arial, verdana, tahoma, sans-serif"] [/font][font="arial, verdana, tahoma, sans-serif"]int y = 50;[/font]
[font="arial, verdana, tahoma, sans-serif"] [/font][font="arial, verdana, tahoma, sans-serif"]boolean is_Y_Even = (y % 2) == 0;[/font]