
how to build this?
import java.util.*; class magicbox{ public static void main(String args[]){ Random r=new Random(); int[][] magic=new int[3][3];
int temp=r.nextInt(9)+1;
boolean tempExist=false;
boolean zeroExist=false;
while(zeroExist){
zeroExist=false;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
int magic=r.nextInt(9)+1;
}
}
L1: for(int a=0;a<3;a++){
for(int b=0;b<3;b++){
if(magic[a][b]==temp){
tempExist=true;
break L1;
}
}
}
if(!tempExist){
magic[i][j]=temp;
}
}
}
//break zeros
L2: for(int x=0;x<3;x++){
for(int y=0;y<3;y++){
if(magic[x][y]==0){
zeroExist=true;
break L2;
}
}
}
//print
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(magic[i][j]+" ");
}
System.out.println();
}
}
}

import java.util.*;
class Mgic2{
public static void main(String []args){ Random r=new Random();
int [][] magic=new int[3][3];
boolean v15=true;
while(v15)
a=new int [3][3];
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
boolean tempexsist=true;
L1:while(tempexsist){
int temp=r.nextInt(9)+1;
for(int k=0;k<3;k++){
for(int l=0;l<3;l++){
if(a[k][l]==temp)continue L1;
}
}
tempexsist=false;
if(!tempexsist){
a[i][j]=temp;
}
}
}
}
v15=a[0][0]+a[0][1]+a[0][2]==15 &&
a[1][0]+a[1][1]+a[1][2]==15 &&
a[2][0]+a[2][1]+a[2][2]==15 &&
a[0][0]+a[1][0]+a[2][0]==15 &&
a[0][1]+a[1][1]+a[2][1]==15 &&
a[0][2]+a[1][2]+a[2][2]==15 &&
a[0][0]+a[1][1]+a[2][2]==15 &&
a[0][2]+a[1][1]+a[2][0]==15 &&
v15=!v15
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.