Chaekyunx’s Weblog “simple informatics cabin”

bwt magic box

Posted on: Oktober 19, 2008

import javax.swing.*;

public class magicboxdyah

{

    public static void main (String args[])

    {

    int array [][];

    int i, j, n;

    int bilangan;

    String Input;

    String Output = “”;

   

    array = new int [100][100];

   

    Input = JOptionPane.showInputDialog(“Inputkan sebuah bilangan asli: “);

    n = Integer.parseInt(Input);

     

    i = 0;          //indeks baris

    j = n/2;        //indeks kolom

   

    for ( bilangan = 1; bilangan <= n*n; bilangan ++)

    {

             array [i][j] = bilangan;

            

             if (bilangan%n == 0)

             i ++;

            

             else

             {

                 i –;

                 j ++;

             }      

                 

             if (i == -1)

             i = n-1;

   

             if(j >= n)

             j = 0;

    }

   

    for (int baris = 0; baris < n; baris ++)

    {

        for(int kolom = 0; kolom < n; kolom ++)

        {

            Output += array [baris][kolom] + “\t”;

        }

        Output = Output + “\n”;

     }   

      

     JTextArea outputArea = new JTextArea ();

     outputArea.setText(Output);

       

     JOptionPane.showMessageDialog(null, outputArea, “output:”,JOptionPane.INFORMATION_MESSAGE);

          

     System.exit(0);

    }

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: