How to make a magic square?

Hello my name is Cesar and I have a cease problemilla I left a program where I have to make a magic square in a MiDlet based on Canvas
Where n is the side from 0 to 9 (n implement only odd) if I could help was the agradeceria beforehand thanks and greetings
My mail [email protected]

Hello I hope you are well, this is the code already done but only programmed into jcreator what I want it to run with wireless toolking as I put the code to run in this programme.
import java.io.*;
class square
int [ ][ ] ar;
int con;
public square(int n)
con=n;
ar=new int [con][con];
void magicsquare()
int ci=((con+1)/2)-1;
int f=0;
ar=new int[con][con];
for(int i=0;i<con*con;i++)
if(ar[f][ci]==0){
ar[f][ci]=i+1;
if(f==0){
f=con-1;
else{
f--;
if(ci==con-1){
ci=0;
else{
ci++;
else{
ci--;
f=f+2;
if(ci<0 && f>con-1){
ci=con-1;
f=1;
else{
if(ci<0){
ci=con-1;
if(f>con-1){
f=0;
ar[f][ci]=i+1;
f--;
ci++;
if(f<0){
f=con-1;
if(ci>con-1){
ci=0;
public static String esimpar(int num)
String res;
num=num%2;
if(num!=0){
res="si";}
else{
res="no";}
return res;
void print(){
for(int i=0;i<con;i++){
for(int j=0;j<con;j++){
System.out.print(ar[i][j]+",");
System.out.println(" ");}
class Exercise
static public void main(String []ars)throws IOException{
BufferedReader leer=new BufferedReader(new InputStreamReader(System.in));
     int op=0;
System.out.println("Write an odd number between 3 and 100:");
op=Integer.parseInt(leer.readLine());
if(op>=3 &&op<=100){
     if(cuadro.esimpar(op)=="si"){
     cuadro magico=new cuadro(op);
magico.cuadromagico();
magico.imprimir();
}else{
System.out.println("The pair number is impossible to continue") ;}
} else{
System.out.println("The number is not within the range 3 to 100");
}

Similar Messages

  • An Idea: How to make the Magic Timeline work with Tracks

    i have thought about this for a title and i think i have found a solution. the magic timeline is pretty cool but with it we lost tracks. for broadcast (not only for that but mostly for it) you need tracks that are assignt in a special way and there is no way around it. so i came up with the following idea…
    to make the magic timeline work with tracks it will be a like an audio compound clip, that will give you full access to the magic time. but it can be outputted to proper tracks assignment.
    current audio compound clips don't show you the video if there is one. this one will. also audio can be tagged to a track so it will automatically drop into the right track. you can of course move the audio from one track to another. moving the clip to another track will auto change the tag to new track. if you copy an audio clip from one track to another, the original clip will keep its tag but the copied one gets the new tag.
    example…
    you do a voice over with all your edits and stuff. then you collapse it to a track (new name to get rid of any sort of confusion). you can tag/name the track to "voice over" or whatever you want and color label it.
    you need to edit, adjust it? no problem! double click it and it will open up and you'll see the magic timeline. edit till you done and click on arrow to return to track view.
    export your movie with proper tracks for broadcast right out of final cut pro x
    in the end your output timeline looks like a timeline from fcp7 before you output it on tape.
    could this work? i believe it could and it would help to make fcpx ready for broadcast.
    i hope this makes some sort of sense to you
    anyway, i hope apple will include this or something like this in an update for fcpx.

    You may be able to get by with just running MDT 2010 for now. *However* you *must* ensure that you are running WinPE 3.1 or greater, If you are unsure, open up a command prompt in WinPE (PRess F8), and run "ver" it should say build 7601 or greater, 7600
    and less is not compatible.
    When done, Run the Dell Advanced Format tool in the Full OS on a deployed machine to verify:  http://del.ly/afhdd  Although it is possible to install an OS on an Advanced Format Drive
    with WInPE 3.0 or earlier, and it may *appear* to work, performance may suffer. The Dell AF tool should tell you if the sectors are aligned properly.
    Additionally, it is also possible that the storage driver you have installed in your image is incompatible with AF drives. Check the Make/Model and check with the Hardware Mfg to see if they have driver that supports AF drives.
    Keith Garner - keithga.wordpress.com

  • How to draw a perfect circle and how to make sure it is perfectly centered inside a square

    How to draw a perfect circle and how to make sure it is perfectly centered inside a square in Photoshop elements using the Ellipse option.

    1. Create a square canvas.
    2. With the Elipse tool, hold down Shift (Shift forces a circle). Draw the circle anywhere on the canvas (Shape 1 in this example).
    3. Simplify the circle layer
    4. Ctrl-click the layer to select the circle.
    5. Copy the selection to the clipboard (Edit > Copy).
    6. Deselect the selection.
    7. Paste from the clipboard (Edit > Paste). The pasted circle (Layer 1) will be centered.
    8. Delete the original circle layer.
    NOTE: Step 6 is the key. This guarantees that the pasted circle will be centered.
    If you want a circle completely within a square you can simply draw and simplify a circle on any shape canvas. Ctlrl-click the circle to to select it and copy to the clipboard.
    Then do File > New from Clipboard. This creates the circle cropped to a square on transparent background.

  • How can I make a Magic eraser brush?

    Hi, does anyone know how I can make a magic eraser brush? and no I don't mean to simply click the Magic eraser tool and then go from there.....what I mena is that I have a black background on one layer then a second layer with a picture of something, I made my own custom brushes and I want to click fill on the black layer so that it will act as a magic eraser brush so that the image below will be able to show through. I know I could just fill the brush pattern as white and then click magic eraser but it looks too clumsy as my custom brush is pretty complicated.
    Thank you in advance for your help

    The magic eraser tool is not a brush tool, so you can't make your own brushes for it.  If you want to use your custom brushes, then I would suggest you use a layer mask to let the background show through, this is also better as it's non-destructive.

  • How to make collage template myself pse8

    I would like to be able to make a template with
    rows of rectangles, squares or circles for collage work. Are there any tutorials
    or can someone point me in the right direction? Thanks

    Malloww,
    There are several ways to do this. Here is one:
    http://www.pixentral.com/show.php?picture=1NmVcTyaLz9i6V7cLOoH4fMslMKr0
    Open blank , new file. I used background color=white, but you can use any color. The resolution should be about the same as that of the pictures which you will display, ultimately.
    Duplicate background layer, work on background copy layer, and shut off visibility of background layer by clicking on its eye icon in the layers palette
    Access the rectangular marquee tool, and in the tool's option bar enter mode>fixed size, and the dimensions for height & width. Drag out the rectangle.
    Open a blank layer. This should be at the top in the layers palette
    Go to Edit>stroke>inside.. I chose color=red. Make the stroke a good sized width. You can select any color.
    Repeat steps 3 & 5 for each position. I have 4 for the purpose of demonstration. Use elliptical marquee tool for circle and ellipse. Hold down shift key as you drag out to get the circle
    Go to Layer>merge down (CTRL+E).
    Access the magic wand tool, and in the tool's option bar "contiguous" should be checked. Click inside the 4 stroke boundaries, sequentially, each time hitting delete on the keyboard. This will punch a hole in each location. The checkered pattern denotes transparency
    Copy, then paste your picture between the background layer and the background copy layer. I did this once here for demonstation
    Use the move tool to position the picture
    Let us know how you make out.

  • How to make new line in JButton.setText()?

    how to make new line in JButton.setText()?
    I want to set the text of jbutton in tow line ,as follows
    | jbutton-line1 |
    | xxxxxxx-line2 |
    i konw i can jbtton.settext("<html>line1<br>line2</html>");
    but i find it's ugly using html,
    is there anyother way to create new line in JButton's Text

    As for the above comment....
    I thought the question was well purposed. Using HTML was not acceptable in this instance, which was made clear, so why critisize his comments? "Using HTML" is a poor solution, it does NOT work in many instances due to browser, OS variations. Usually the "common answer" is never a COMPLETE answer.
    Possible Solution:
    Use JLabels to render the text on the button.
    import javax.swing.*;
    import java.awt.*;
    public class ButtonMaker {
    public static void makeButton(JButton jb, String[] titleList) {
    jb.setLayout(new FlowLayout());
    for (int i = 0; i < titleList.length; i++) {
    JLabel tmpLabel = new JLabel(titleList);
    tmpLabel.setForeground(Color.black);
    jb.add(tmpLabel);
    public static void clearButton(JButton jb) {
    Component[] cList = jb.getComponents();
    for (int i = 0; i < cList.length; i++) {
    if (cList[i] instanceof JLabel)
    jb.remove(cList[i]);
    Known Limitations:
    1. Flowlayout does not work well with single line text buttons... perhaps another layout manager may work better for various buttonsizes-linenumber combos.
    2. Mac OSX : The default UI for Mac OS X (and above it seems), is to have rounded edged buttons. These rounded edges are destoryed when using JLabels, leaving a square, blocky button in its place.
    POSSIBLE SOLUTION:
    (this is ugly and time consuming)
    - create images of the button with text on them.

  • MOVED: how to make a good flow in the case?

    This topic has been moved to Off Topic Technical.
    how to make a good flow in the case?

    Browser variation is something we must all deal with.  For best results, begin projects with a clear idea of what type of layout you need (1-column, 2-column, 3-column or Multi-column grid).  Then get a CSS Layout that meets your requirements.
    PVII CSS Templates are rock solid & thoroughly tested to perform well in all browsers (commercial product)
    http://www.projectseven.com/products/index.htm
    CSS Layout Magic (commercial extension for Dreamweaver)
    http://www.projectseven.com/products/templates/pagepacks/cssmagic/index.htm
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb

  • I subscribed for itunes imatch - it works perfectly on my i-pad and iPhone - however on my macbook - my iTunes can no longer find my songs - i don't know how to make it look to the cloud to play my music

    i subscribed for itunes imatch - it works perfectly on my i-pad and iPhone - however on my macbook - my iTunes can no longer find my songs - i don't know how to make it look to the cloud to play my music - i think it keeps trying to find on the external harddrive where i used to keep my music

    Of course iTunes is looking for the music on the external HDD. Enabling iTunes Match does not magically change the location of the iTunes library to the cloud.
    To play the music either plug the external HDD back into your computer or create a new, empty library to use for streaming the iTM content. The latter can be accomplished by holding down the Option key when launching iTunes, choosing "create library" then enabling iTunes Match on the new library. DO NOT have iTunes scan your HDD for music.

  • How to make a Java program that recognises a function of two variables...

    How to make a Java program that recognises a function of two variables to assign values to that?
    First I will give an example and then do the question.
    Ex1.
    We have any function, eg.y = x ^ 2 + 1 (read 'y' equals 'x' high to the square), a function of the second degree.
    To build the graph of this function attach values to 'x' to find the values of 'y'
    And thus mount the pair ordered (x, y) which represents a point on the Cartesian plane.
    Assigning values to 'x' 'we can build up a table that gives us the pairs ordered:
    We can use any numbers, but arfer interval [-3.3]
    X | y = x ^ 2 + 1
    -3 | Y = (-3) ^ 2 +1 = 10
    -2 | Y = (-2) ^ 2 +1 = 5
    -1 | Y = (-1) ^ 2 +1 = 2
    0 | y = (0) ^ 2 +1 = 1
    1 | y = (1) ^ 2 +1 = 2
    2 | y = (2) ^ 2 +1 = 5
    3 | y = (3) ^ 2 +1 = 10
    We then ordered the pairs:
    (-3.10), (-2.5); (-1.2), (0,1), (1,2), (2,5), (3,10)
    Tabem that can be represented by a table:
    X | y
    -3 | Y = 10
    -2 | Y = 5
    -1 | Y = 2
    0 | y = 1
    1 | y = 2
    2 | y = 5
    3 | y = 10
    Now I begin to explain my doubts.
    See this program:
    Ex2
    * To change this template, choose Tools | Templates
    * And open the template in the editor.
    Encontrando_o_valor_de_y package;
    * @ Author des Soldat Gottes
    Import javax.swing.JOptionPane;
    Public class (Main
    * @ Param args the command line arguments
    Public static void main (String [] args) (
    Int x, y;
    String x1;
    X1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
    "Assign a value for 'x',"); / / receives a value for the function y = x + 1
    X = Integer.parseInt (x1); / / tranforma String in int
    Y = x + 1; / / receives the value of 'x' and calculates' y '
    JOptionPane.showMessageDialog (null, "The value of 'y' is: \ t \ t" + y);
    / / Displays the value of 'y'
    System.exit (0);
    We see that the program receives above a value for 'x' and replaces the function contained in the program, y = x + 1, and so is the value of the variable 'y'.
    In: x1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
    "Assign a value for 'x',");
    The entry is a number and that number is assigned aa ja existing function in the (y = x + 1).
    The question is: would it be possible to come to a function?
    Ex: the program ask: DIGITE THE FUNCTION?
    The USUARIO DIGITARIA A FUNCTION ANY, TYPE: y = x ^ 2 +1
    The program would recognize the function and give numerical values to that function as Ex1, at the beginning of this text.
    And then to find the values of the x and y launch a table.
    It would be possible that?
    By invez of entering with a number so that the program sustitua a function ja existing as Ex2, seen above, entering with a function quaquer (type: y = x ^ 2 +1) for the program atribuisse values to that function and then create a table of values as Ex1.
    I hope it has been easier to understand my doubts now.
    Thank you for your attention!
    God bless!

    rafaelmenezes wrote:
    Thanks for the explanation, could understand what fly said.
    But as it applied to a program?
    How to create a program that recognizes that the entry coefficients?Are you asking about how to parse out the coefficients from the string "3x^4 + 4x^3 - 8x^2 + 5x^1 + 2x^0"? If you define the format to strictly follow that example, this should get you started:
    Strip out the spaces
    Split the String on "x^"
    That should give you [3, 4+4, 3-8, 2+5, 1+2, 0]
    Split each resulting String on "+ | -", preserving the operator as a token so you can apply the correct sign to the coeff.
    That should leave you with [3, 4, +, 4, 3, -, 8, 2, +, 5, 1, +, 2, 0]. Every other number is a coeff, the rest are the degrees.
    You can strip out the +, since those coeffs are already positive, and strip out the - after negating the following number. This is all assuming that you have to write this yourself. There is no doubt already a library or 5 out there that does this for you.

  • How to make a appointment on line

    I have a problem on the screen on ipad, how to make a appointment on line for fixing it ? Could you show me the link ?

    Used the Pen tool, but click on the correct icon on the top left on the Options Bar. That way you can get a Path instead of a Shape Layer.
    Once you have your Path you can stroke it with a Brush or any drawing tool. Various options appear in the Brushes palette. For a dotted line you will need to increase the spacing. If you want dashes, use a square brush and set the Angle Jitter to Direction.

  • How can i get magic voice changer on my nokia c6?

    hi just wondering how can i get magic voice changer on my nokia c6? please if anyone can help thanks!

    Make sure your own music files are saved in the proper folder (Digital sounds) whether in your memory card or the phone memory, the location should still be:
    Sound Clips > Digital Sounds.
    If your songs/mp3s are saved anywhere else, it will not show up as a selectable ringing tone.
    You can move your songs through File Manager on your phone if they are in the wrong location (Options > Move to folder).
    Hope that clarifies it for you.
    "Try not. Do or do not, there is no try."
    If you found someone's comments helpful or like what that person has to say, please give some Kudos to the post!

  • How to make a pressure sensitive brush in CS3?

    Hi!
    Is there someone out there who knows how to make a brush similar to this? I've been trying to figure it out for several hours now, but nothing works!
    Daniel

    Sorry but you aren't going to get something that looks like that from a pressure sensitive brush in Illustrator.
    The colors and groupings of blocks are too random to be a repeating pattern (a simple one, anyway) and the order is too consistent to be something like a scatter brush. That said, you *can* do this with a brush but it won't be pressure sensitive and it will require a degree of setup.
    Start by building a row of blocks. Mine is a simple pattern with a few pieces removed and not terribly interesting looking but hopefully it'll give you the idea of what I mean:
    Group everything and then go up to Effect> 3D> Rotate
    Set your X, Y, And Perspective parameters to taste. Keep the Z axes (the blue one) at zero:
    Go to Object> Expand Appearance You'll notice that Illustrator has put a clipping mask around your squares (transparent rectangle) Delete it.
    Take everything you have and drag it over to the brush panel and make a new Art Brush:
    Now you can select that brush and paint with it though you'll get better results by stroking a path you've drawn with the pen tool:
    A couple of things to keep in mind:
    You'll need to consider your ultimate length when creating the brush. Longer or more wavy lines will require more squares. My squares look a little skewed because I didn't bother to make my pattern very long. A longer row will improve the look of this but hopefully my example is enough to give you the idea.
    For generating the square colors, you might want to try the random fills script available from James talmage's page and then use live color to tint everything for you.

  • How to make mouse click event to display image on 2D array?

    Hi! beginner programmer here looking for some guidance, hints and tips.
    I'm making a game of "Connect 4" and using a 2D array to display the board which is 7x6 in size.
    What i want to do is that when the player clicks on one of the squares, one of the 2 game pieces(red.png or yellow.png) will appear on the respective coordinates of the 2D array and check if the square in the first row is empty and if true, places/display
    the game piece, else it places the piece on the first empty square.
    Since i've never worked with WinForms or 2d arrays before i'm not sure how to initiate it.
    What i was considering in pseudocode was:
    pb_Mouseclick(object sender, MouseEventArgs e)
    if(e.Button==MouseButtons.Left)
    Picturebox pb=(Picturebox)sender;
    clickLocation.X= e.Location.X + pb.Location.X, pieceArray[row];
    clickLocation.Y=e.Location.Y + pb.Location.Y, pieceArray[col];
    if(pieceArray[row, col] == null)
    if(player1.IsStarter==true) selectedimage(@"yellow.png")
    else
    selectedimage(@"red.png")
    else {
    bool empty= false;
    for(int row=0; row<height - 1; row++)
    for(int col=0; col<width; col++)
    if(pieceArray[row, col] ==null)
    empty=true;
    (Add gamepiece)
    This is what i've come up with so far, but it's just some theorycrafting, not sure if i should use a while-loop instead...
    Hope anyone can give me some insight on how to make it work and if the logic of my pseudocode is correct for what i want according to my earlier explanation.
    Many thanks in advance!
    Regards
    Gabbelino
    Student at the University of Borås, Sweden

    Hi Gabbelino,
    I could not understand your game rule clearly, and could you make explanation for me?
    1.>> when the player clicks on one of the squares
    What were the squares? Did it like dice or anything else?
    2.>> one of the 2 game pieces(red.png or yellow.png) will appear on the respective coordinates of the 2D array
    What is the 2 game pieces? Could you show us the two pictures?
    3.>> check if the square in the first row is empty and if true, places/display the game piece, else it places the piece on the first empty square
    Could you show us where places/display the game piece?
    Best Regards,
    Tony
    Help each other

  • How to make symbol become designated drop area?

    Previvious discussion http://forums.adobe.com/message/5173983#5173983
    ok this is what I got so far, four squares on the grid, respectively named: squareC1, squareC2, squareC3, squareC4. Now I want the square that we named smallSquareName to be able to fit in any of the other four, how do I tell AS3 that smallSquareName can fit in any of these squareC1, squareC2, squareC3, squareC4, at the user’s will, because as it is now smallSquareName can roam freely all over the screen (not that it is a bad thing) But just like a game of chess I want smallSquareName to move according to the guidelines of the game.
    Anticipating thanks

    well I think I understand the logic in that ,however I'm not sure that I know how to accomplish it, first of all I think that I got the Array correct, however when I try to use the  hitTestObject mentioned I’m getting all sort of error,  so I was thinking if it’s ok for me to send you (or anyone willing to help)my files so that you can help me correct the mistakes. My aim is to make the red square fit into any of the bleu. 
    here is the file http://www9.zippyshare.com/v/76591404/file.html
    Anticipating thanks

  • How do I eliminate random squares from pdf output?

    When I create a PDF from FrameMaker 8, random squares appear in the output.  How can I eliminate these squares?  And is the issue with the Distiller, Distiller settings, or with FrameMaker or what?  The squares do not replace characters, but are overtop of them.
    Thank you,
    Erin

    Arnis,
    The squares are only appearing on the copyright page.  I don’t know why this would be.   It only has text.  And the fonts used on that page are also used in the rest of the book.  Here is an example of the squares I am seeing.  Are you able to see this?
    The rest of the document has step by step instructions, some pictures and tables, paragraphs....I don't know the original source of the content in the files.  It could have started in Word.   There are some coding examples in the text (Monotype), but that font is not used in the file that has the issues.  I guess the copyright page that has the issues could have been copied from another document at some point.  Would I need to do anything to that content to make it acceptable?
    Thank you,
    Erin

Maybe you are looking for