Share on Google+Share on Google+

supun dahanayaka
Magicbox 2
1 Answer(s)      4 years and 4 months ago
Posted in : Java Beginners

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;


    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++){
                        break L1;

    //break zeros
    L2: for(int x=0;x<3;x++){
            for(int y=0;y<3;y++){
                    break L2;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            System.out.print(magic[i][j]+" ");




View Answers

December 3, 2012 at 7:56 PM

import java.util.*;

class Mgic2{

public static void main(String []args){ Random r=new Random();

    int [][] magic=new int[3][3];
    boolean v15=true;
        a=new int [3][3];

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
    boolean tempexsist=true;

                                                       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;

    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 &&
    for(int i=0;i<3;i++){
       for(int j=0;j<3;j++){
    System.out.print(a[i][j]+" ");


Related Tutorials/Questions & Answers:
Magicbox 2
Magicbox 2  how to build this? import java.util.*; class magicbox...; } } } } 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 &&
use is of 2
use is of 2  why we use 2 in "Integer.parseInt(str,2);" for binary to decimal conversion..??   ya i got it... because binary contain only two o and here use 2...same as octal has 8
Struts 2
Struts 2  we can extend DispatchAction class to implement a common session validation in struts 1.x. how to do the same in the struts2
Struts 2
Struts 2   I am just new to struts 2 and need to do the task. I have a requirement like this : when i click on link like Customer , this will display all the customers , address from a database table using jdbc and the screen
Struts 2
Struts 2  I am getting the following error.pls help me out. The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has
new 2
new 2  <[email protected] import="java.util.ArrayList"%> <[email protected]..; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 sevelet @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 import; import; import
Echo 2
Echo 2       Echo 2 allows you to code Ajax apps in pure Java (Demo)which automatically generates HTML and Javascript. Read full Description
FireFox 2
FireFox 2       The award... to do on the Web, and Firefox 2 is full of helpful features to make your... Add-ons that enhance Firefox. It?s easy to personalize Firefox 2
Thunderbird 2
Thunderbird 2       Mozilla?s Thunderbird 2 email application is more powerful than ever. It?s now... Information Organized Thunderbird 2 features many new enhancements to help
struts 2 testing
struts 2 testing  can i get an example for struts 2 action class unit test
regarding struts 2
regarding struts 2   is it not possible to get values from into our application in struts 2
Struts 2 - Validation - Struts
Struts 2 - Validation annotations  digging for a simple struts 2 validation annotations example
2's Complement
2's Complement  hi Can anyone plsss tell me the 2's complement java program... Thanks in advance
Where to learn Struts 2?
Where to learn Struts 2?  Hi, I am beginner in Struts and trying to find good tutorial to learn Struts 2 framework. My project is in Struts 2 and soon I have to work on the project. Let's know where to learn the Struts 2
Struts 2 Video Tutorial
Struts 2 Video Tutorial  I think its easy to learn from Struts 2 Video Tutorial. What is the url of Struts 2 Video Tutorial on website... your are right. You can learn Struts 2 very easily with the Struts 2 Video
Struts 2 online tutorial
Struts 2 online tutorial  Where to learn struts 2 online tutorial? Is there any good tutorials on for learning struts 2 online tutorial?   Yes, We have many tutorials for learning Struts 2 online through
What is Struts 2 framework
What is Struts 2 framework  Hi, I am new to the Java web programming. I have completed JSP, Servlet and HTML. Now I want to learn Struts 2. Tell me what is Struts 2? Thanks
Struts 2 + hibernate
Struts 2 + hibernate  How to integrate Struts 2 and Hibernate? Its urgent please help!!   See the example give below.. for integrating struts 2 and hibernate. Struts2.2.1 and hibernate integration application Integrate
Struts 2 + Hibernate
Struts 2 + Hibernate  From where can i get good tutorial from integrating struts 2 with hibernate , which explains step by step procedure in integration and to build web applications
struts 2 project samples
struts 2 project samples  please forward struts 2 sample projects like hotel management system. i've done with general login application and all. Ur answers are appreciated. Thanks in advance Raneesh
Strurt 2 TLD - WebSevices
Strurt 2 TLD  pls any one can send me either link to download or actual TLD files of struts 2 i nead the TLD files but i could not found
struts 2 tabbedpanel - Struts
struts 2 tabbedpanel  Hi Friend do I change the background color of a tab? bye bye
Query Question 2
Query Question 2  Want to displays the name and ID of all departments with the names of the employees in that department. SELECT * FROM employee is my result
Compare 2 files
Compare 2 files  I would like to compare 2 files in Java. please send me the code snipt for this scenario: File1... file 1 and 2. The file name will normally be the last 16 characters of a line
Maven 2 - Maven
Maven 2   Hi, I m new to Maven 2 and in process to implement Maven2. I have browse in the net and got my Maven 2 installed but now I m facing few concerns on creating a small project. Please help me in this regard Thanks
Printing 2 arrays
Printing 2 arrays  Hi, I have 2 arrays: String [] head = {"Name... want this 2 arrays to be printed out in the following manner: head[0] tab personal[0] head[1] tab personal[1] head[2] tab personal [2] I tried different
Struts 2 - Beganner
Struts 2 - Beganner  Hi ! I am new to Struts2 and I need clarification over Difference between Action Proxy and Action Mapper in struts2 and When both perform their activity?????? Many Thanks Venkateshlu
zend framework 2
zend framework 2  i am new in zf2 and i want to develop a website in zf2 so can anyone help me to figure out the(login and signup page) with database
struts 2 mysql
struts 2 mysql  In the example : how is the username and password(in insertdata.jsp) which is entered by the user is transferred to the { ("INSERT employee VALUES
Divide 2 numbers
Divide 2 numbers  Write a java program to divide 2 numbers. Avoid division by zeor by catching the exception.   class Divide { public static void main(String[] args) { try{ int num1=8
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code


Advertisement null