#Beginner Java question

1 messages · Page 1 of 1 (latest)

arctic quartz
#

I was trying this question saying to write a function that generated cubes between S and
N. Could anyone just explain what I done wrongl tried my best with this question and took my time with it. I was guessing it was nested for loops but then I failed with trying to make it work. Now I only left it as one loop and tried to make sense of it but then its asking me to return a String since thats the return type of the method. Any help I would be thankful

signal boughBOT
#

<@&987246399047479336> please have a look, thanks.

little sun
#

why do you set S = 0?

#

you should introduce a loop variable that starts at S

#

also you need to accumulate the results

stray quest
#

mind sharing the error message with us? humans are bad compilers and i cant spot the issue right away

little sun
#

and not return in the first loop cycle

pulsar iron
#

else is unnecessary here btw

stray quest
#

oh, ur missing a return in all cases

wraith wolf
#

You are early enough in your journey that it might be worth it to learn things a bit more deeply

signal boughBOT
#

For learning Java, we recommend the ebook Modern Java:
https://javabook.mccue.dev/

It is completely free, meant for beginners and covers all content relevant for the first year. It is a great way to learn Java from the ground up.
If you run into any questions during your journey, you may ask us in #1051826284008853505 and we will help cat_thumbs_up

If you prefer a more traditional learning experience, we also recommend MOOC:
https://java-programming.mooc.fi/
This is the course used by the University of Helsinki to teach their students programming in their first year, also completely free.

arctic quartz
little sun
#

int i = S;

arctic quartz
#

One second

pulsar iron
#

why did u set the S in the for loop? or why did u set it out of it?

wraith wolf
#

Also strong recommendation to not use AI at all

pulsar iron
#

why do you return if S is smaller than 0 when u set it to 0 anyways?

arctic quartz
arctic quartz
#

Oh

wraith wolf
#

Like okay let me justify that

#

You are currently not at the point where what you need is practice problems

#

You have a weak understanding of both mechanics and how to write software

wraith wolf
#

And in general AI is playing with fire. There are practice problems out there when you need them

pulsar iron
# arctic quartz Hmm ur right

if you are using an integer in a for loop, you can define it within the for loop, and absolutely no need to define it outside the class. make it into a local variable instead

arctic quartz
#

Is the for loop okay now

little sun
#

no

wraith wolf
#

No

little sun
#

you return after the first cycle

wraith wolf
#

Also there is the snipping tool for taking screenshots

little sun
#

so the loop does not loop

wraith wolf
#

You don't need to use your phone

little sun
#

also i = S, not 0, you want the first cube to be S

arctic quartz
#

True

arctic quartz
wraith wolf
#

Genuine advice is to stop and go back to basics

arctic quartz
wraith wolf
#

You aren't ready for this problem yet

arctic quartz
#

Ill revise loops again

signal boughBOT
#

For learning Java, we recommend the ebook Modern Java:
https://javabook.mccue.dev/

It is completely free, meant for beginners and covers all content relevant for the first year. It is a great way to learn Java from the ground up.
If you run into any questions during your journey, you may ask us in #1051826284008853505 and we will help cat_thumbs_up

If you prefer a more traditional learning experience, we also recommend MOOC:
https://java-programming.mooc.fi/
This is the course used by the University of Helsinki to teach their students programming in their first year, also completely free.

arctic quartz
#

Thankz

pulsar iron
#

good tut

#

tells the basics (syntax, logic, etc.)

pulsar iron
#

dont matter

wraith wolf
arctic quartz
#

Cool

wraith wolf
#

And genuinely go from the start

arctic quartz
#

Definitely

restive briar