Tuesday, February 23, 2010

How To Write Motion To Object Letter



wants us to do a magic box, that is, it wants to create a matrix of size 3 * 3 matrix, the data collected as a line, summed up in the colon, cross will be the same as the aggregated totals. Example, the hand that add up as we saw below Collect what you'll find the value of 15. 3 * 3 the size of the user is not getting us to create a data matrix and wants us to check if you have magic. Below that wants to be written into the program using methods of

. Programma che

QuadratoMagico

verifica se una matrice quadrata di un Scrivere inter e 's

quadrato Magico, ovvero se la Somma di ogni riga degli element,
Magico 3x3:

2 9 4 6 1 8 7 5 3

E 'possibile definire a class for this purpose and likely QuadratoMagico

has the following methods and constructors: public

QuadratoMagico (int s) that creates a magic square of size sx s.

public void fill (): filling the array of numbers of QuadratoMagico with values \u200b\u200btaken from the keyboard.

public void print (): print to video to the array of numbers contained in the type QuadratoMagico.

public boolean check () which returns true if the array is a magic square, false otherwise.

write a simple main ():

a) creates an object type of magic square of size 3x3;

b) requires input from keys of the array elements;

c) check whether the square and the 'magic or not;

d) printing the result of computation.

sample run:

Inserting the values \u200b\u200bof the square of size 3

1 2 3 4 5 6 7 8 9

The square:

1 2 3 4 5 6 7 8

9

not 'magic

public class QuadratoMagico2

{/ * mat Adinda 2 boyutlu olusturuyoruz Matris olusturabilmek dizi icin * /

int [] [] mat;

public QuadratoMagico2 (int size) {

/ * mat degiskenimize dizi boyutunu belirliyoruz * /

mat = new int [size] [size];}

riempi public void () {

/ * array of data entering the matrix * / int n = mat.length

;

for (int i = 0; i \u0026lt;n, i + +) {

for (int j = 0, j \u0026lt;n, j + +) {

mat [i] [j] = Console.leggiIntero ();}

}} public boolean

verifica () {

/ * the first one to make comparing the data we collect from us because they want a magic box and cross for the girth of each line will be the same collection. * / Int n = mat.length

;

int Somma = 0;

int s;

for (int j = 0, j \u0026lt;n, j + +) {

Somma + = mat [0] [j];

}

/ * now In the first line after collecting the other lines that control will only, each row sums equal to rue the value returns if not false, * /

for (int i = 1; i \u0026lt;n, i + +) {

n = 0;

for (int j = 0, j \u0026lt;n, j + +) {

s + = mat [i] [j];

}

if (s! = Somma) {

return false;

}

}

/ * now the columns of the control will only * /

for (int i = 0; i \u0026lt;n, i + +) {

n = 0;

for (int j = 0, j \u0026lt;n, j + +) {

s + = mat [i] [j];

} if (s! = Somma)

{return false;}

} / * * We will now check for the cross /

s = 0 ;

for (int i = 0; i \u0026lt;n, i + +) {

s + = mat [i] [i];

}

if (s! = Somma) {

return false;

} n = 0;

for (int j = 0, j \u0026lt;n, j + +) {

s + = mat [j] [n - 1 - j];

}

if (s! = Somme) {

return false ;

} return true;}

dies

public void () {

/ * Matrisi yazdiriyoruz screens * / int N =

mat.length;

for (int i = 0; i \u0026lt; N; i + +) {

Console.nuovaLinea ();

for (int j = 0, j \u0026lt;N, j + +) {

Console.scriviInt (mat [i] [j]);}

Console.nuovaLinea

} (); } Public static void

main (String [] args) {

/ * determine the size of the matrix * / int size = 3

;

QuadratoMagico2 QuadratoMagico2 qm = new (to you);

/ * function qm reference set it to * /

Console.scriviStringa ("inserimento dei dei valor del quadrato dimesione");

Console.scriviIntero (you);

/ * received from the user is entering data and screen print the array * /

qm.riempi ( );

Console.scriviStringa ("provincial quadrato è");

qm.stampa ();

/ * check if you have the magic of the matrix We are * / boolean

qm.verifica risul = ();

if (risul) {

Console.scriviStringa ("è Magico");} else {

Console.scriviStringa ("non è Magico") ;

}}}

0 comments:

Post a Comment