#Neater code
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @fringe meteor! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
create a method?
just put finding sum, min and max in same loop
i tried it just but for some reason it says j value not initialized
because you need to put them in block { }
for (int j=(middle-count);j<=middle+count;j++) {
sum += array[i][j];
if (array[i][j] > max) max = array[i][j];
if (array[i][j] < min) min = array[i][j];
} ```
yeah ther eyou only have single statements as the body of your loops
also you could really do with better formatting on the loop header and your conditions
and better formatting in general
mainly indents and spacing
void runInLoop(IntConsumer toRun, int middle, int count){
for(int j=middle-count;j<=middle.count;j++){
toRun.accept(j);
}
}
i see
this is method right?
this worked i got it
this is an alternative if you want to run the loop 3 times
with different code
that's something i wanted to work on how do i make it look neater in general?
Are you using an IDE?
like how do i know when to put indents and stuff
have consistent spacing between tokens, like between operators and operands
a + b vs a+b
i think so
wherever you have a nested context
netbeans IDE 16
Does Ctrl+Shift+F work?
it popped up find in projects
lol
is there a preferred one or it's up to preference as long as it's consistent?
some are near universal, some have multiple existing styles
most important thing is to stay consistent yeah
from there, try to follow the language or codebase convention
did it just arrange my code for me?
having correct indents at all and having spacing between tokens are 2 of the "near universal" ones
actually no, spacing for operations is near universal, not so for other tokens
oh ya quick question as well
is there something else i can use rather than 1000000
there are some (pretty uncommon afaik) styles that prescribe no space between if and its condition, or between an array's {} and its elements, for example
Integer.MAX_VALUE and Integer.MIN_VALUE
i see
MAX_VALUE for min and MIN_VALUE for max, to be clear
Before your post will be closed, would you like to express your gratitude to any of the people who helped you? When you're done, click I'm done here. Close this post!.