magicbox

magicbox

How to complete this?

import java.util.*; class Example{ public static void main(String args[]){ Random r=new Random(); int[][] m=new int[3][3];

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            int x=r.nextInt(9)+1;
            System.out.println("ij"+i+" "+j+" "+x);

            boolean xExist=false;

            for(int a=0;a<3;a++){
                for(int b=0;b<3;b++){
                    if(x==m[a][b]){
                        xExist=true;
                    }
                }
            }
            if(!xExist){
                m[i][j]=x;
            }
        }
    }
    //print
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            System.out.println(m[i][j]+" ");
        }
        System.out.println();
    }
}

}

View Answers

December 1, 2012 at 5:53 PM

Here is your required code.

import java.util.*;
class Example2{
    public static void main(String args[]){
        Random r=new Random(); 
        int[][] m=new int[3][3];

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            int x=r.nextInt(9)+1;
            System.out.println("ij"+i+" "+j+" "+x);

            boolean xExist=false;

            for(int a=0;a<3;a++){
                for(int b=0;b<3;b++){
                    if(x==m[a][b]){
                        xExist=true;
                    }
                }
            }
            if(!xExist){
                m[i][j]=x;
            }
        }
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            System.out.print(m[i][j]+" ");
        }
        System.out.println();
    }
}

}









Related Tutorials/Questions & Answers:
ModuleNotFoundError: No module named 'magicbox'
ModuleNotFoundError: No module named 'magicbox'  Hi, My Python... 'magicbox' How to remove the ModuleNotFoundError: No module named 'magicbox... to install padas library. You can install magicbox python with following
magicbox
Advertisements
Magicbox 2
Magicbox 2  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

Ads