Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the code I did for this activity. Everything works fine except I can't figure out a way to make sure the user enters

This is the code I did for this activity. Everything works fine except I can't figure out a way to make sure the user enters only positive integers. EVERYTHING ELSE WORKS. Please add to my code.

import java.util.Scanner; class Arraytwod { public static void main(String []args) { Scanner reader = new Scanner(System.in); System.out.println("Enter 16 numbers POSITIVE integers and we will determine if it is a magic square."); int count=1; int [][] arr= new int[4][4]; for (int r=0; r

image text in transcribed

Part III: 2-D Arrays A magic square is a two-dimensional array of positive integers such that the sum of each row, column, and diagonal is the same constant The following example is a magic square whose constant is 34: 2 13 5 10 8 16 7 12 15 141 Write a program that takes 16 integers as inputs. The program should determine whether or not the square is a magic square and display the result. Show the grid of numbers (do not worry about making the boxes). Do not allow the user to enter in negative numbers. You should keep asking until all 16 numbers are positive

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions