SquareTest - for (int row = 0; row < size; row++)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// **************************************************************** // SquareTest.java // // Uses the Square class to read in square data and tell if // each square is magic. // // **************************************************************** import java.util.Scanner; public class SquareTest { public static void main(String[] args) { Scanner scan = new Scanner (System.in); int count = 1; //count which square we're on int size = scan.nextInt(); //size of next square //Expecting -1 at bottom of input file while (size != -1) { //create a new Square of the given size Square magicSquare = new Square(size); //call its read method to read the values of the square magicSquare.readSquare(scan); System.out.println("\n******** Square " + count + " ********"); //print the square magicSquare.printSquare(); //print the sums of its rows
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for (int row = 0; row < size; row++) System.out.println ("Sum of row " + row + ": " + magicSquare.sumRow(row)); //print the sums of its columns for (int col = 0; col < size; col++) System.out.println ("Sum of column " + col + ": " + magicSquare.sumCol(col)); //print the sum of the main diagonal System.out.println ("Sum of the main diagonal: " + magicSquare.sumMainDiag()); //print the sum of the other diagonal System.out.println ("Sum of the other diagonal: " + magicSquare.sumOtherDiag()); //determine and print whether it is a magic square if (magicSquare.magic()) System.out.println ("It's a magic square!"); else System.out.println ("It's not a magic square!"); System.out.println(); //get size of next square size = scan.nextInt(); count++; } } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Page1 / 2

SquareTest - for (int row = 0; row < size; row++)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online