#Neater code

1 messages · Page 1 of 1 (latest)

fringe meteor
#

Is it possible to run this code without writing for (int j=(middle-count);j<=middle+count;j++) 3 times?

maiden fernBOT
#

This post has been reserved for your question.

Hey @fringe meteor! Please use /close or the Close Post button 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.

limpid obsidian
#

create a method?

fringe meteor
hollow relic
fringe meteor
#

i tried it just but for some reason it says j value not initialized

hollow relic
#

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];
} ```
viral nimbus
#

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

limpid obsidian
#
void runInLoop(IntConsumer toRun, int middle, int count){
    for(int j=middle-count;j<=middle.count;j++){
        toRun.accept(j);
    }
}
fringe meteor
#

i see

limpid obsidian
#

with different code

fringe meteor
limpid obsidian
#

Are you using an IDE?

fringe meteor
#

like how do i know when to put indents and stuff

viral nimbus
#

have consistent spacing between tokens, like between operators and operands
a + b vs a+b

fringe meteor
viral nimbus
fringe meteor
#

netbeans IDE 16

limpid obsidian
#

Does Ctrl+Shift+F work?

fringe meteor
viral nimbus
#

lol

fringe meteor
limpid obsidian
#

alth +shift+f

#

my fault

fringe meteor
#

ouh

#

its

viral nimbus
fringe meteor
#

did it just arrange my code for me?

viral nimbus
#

having correct indents at all and having spacing between tokens are 2 of the "near universal" ones

fringe meteor
#

i see

#

alright got it

viral nimbus
#

actually no, spacing for operations is near universal, not so for other tokens

fringe meteor
#

oh ya quick question as well

fringe meteor
viral nimbus
#

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

viral nimbus
viral nimbus
#

MAX_VALUE for min and MIN_VALUE for max, to be clear

fringe meteor
#

ahhhh

#

i see

#

okok got it

maiden fernBOT
# maiden fern

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!.