Revision e40ffe8c-33c7-40dd-8a04-1bd6f3e122a3 - Code Golf Stack Exchange

#Java 8, 247 bytes

<!-- language-all: lang-java -->

 v->{int a[][]=new int[7][7],i=7,j,k;for(;i-->0;)for(j=7;j-->0;)a[i][j]=(int)(Math.random()*9+1);String r="";for(;++i<7;r+="\n")for(j=0;j<7;r+=(k=a[i][j])>9|j++%2<1?k+" ":k+" ")for(k=0;k<9;k++)if(i%2>0&j%2>0)a[i][j]+=a[i+k/3-1][j+k%3-1];return r;}

**Explanation:**

[Try it here.](https://tio.run/##NZBBboMwEEX3OcUIKZVdA03SBUqN6QmSTaVuKAuXkNY2GGQMVZVydmoLIo1G82f0v0ZP8pFHbVdpeVFzWfO@hxMX@rYBENpW5srLCs5eArxZI/QXlOi9FRcYMXXbaeNab7kVJZxBA4N5jLKb8wLPi7xguvrxSXlSuAoFS0IZKnptDaIiirIdxX6WLKFykTwXRS4LhpwLoxO337Hh@tI2CD8eyR7T9Q3DgmDJIUSkCTWEBR86WON2VC47pNiaiLPjnyRke0j3r4oEELz4DotDOYdKj1QRgsUVie0h2z1I3@8PEZ9D1NNztHeSqK0fqKnsYDQYOs0eh6tu@KwdjJXJ6FE1jiha3s4L4HjF@dvbqonbwcadO9laIx2XSA91jVe20/wP)

 v->{ // Method with empty unused parameter and String return-type
 int a[][]=new int[7][7], // Integer-matrix with 7x7 zeroes
 i=7,j,k; // Index integers (`i` starting at 7)
 for(;i-->0;) // Loop (1) from 6 down to 0 (inclusive)
 for(j=7;j-->0;) // Inner loop (2) from 6 down to 0 (inclusive)
 a[i][j]=(int)(Math.random()*9+1);
 // Fill the current cell with a random 1-9 integer
 // End of inner loop (2) (implicit / single-line body)
 // End of loop (1) (implicit / single-line body)
 String r=""; // Result-String
 for(;++i<7; // Loop (3) from 0 to 7 (exclusive)
 r+="\n") // After every iteration: append a new-line to the result
 for(j=0;j<7; // Inner loop (4) from 0 to 7 (exclusive)
 r+= // After every iteration: append the result-String with:
 (k=a[i][j])>9 // If the current number has 2 digits,
 |j++%2<1? // or it's an odd column (1st/3rd/5th)
 k+" " // Append the current number + one space
 : // Else:
 k+" ") // Append the current number + two spaces
 for(k=0;k<9;k++) // Inner loop (5) from 0 to 9 (exlusive)
 if(i%2>0&j%2>0) // If both indexes `i` and `j` are odd
 a[i][j]+= // Sum the item at that location with:
 a[i+k/3-1][j+k%3-1];
 // The numbers surrounding it
 // End of inner loop (5) (implicit / single-line body)
 // End of inner loop (4) (implicit / single-line body)
 // End of loop (3) (implicit / single-line body)
 return r; // Return the result-String
 } // End of method

AltStyle によって変換されたページ (->オリジナル) /