Question

In this assignment, we will show you the benefits of test driven development. You will produce...

In this assignment, we will show you the benefits of test driven development. You will produce two pieces of code: Squarelotron.java and SquarelotronTest.java.

This assignment deals with 2-dimensional arrays or matrices. They are not all that different from the 1-dimensional arrays that you saw in the video. Just think of them as an array of arrays.

2D arrays are usually displayed similar to a matrix.

For example to deal with the matrix below,

1 2 3

4 5 6

7 8 9

We provide the following code to help you understand 2-dimensional arrays:

int[][] myMatrix = new int[3][3]

myMatrix[0][0] = 1;

myMatrix[0][1] = 2;

myMatrix[0][2] = 3;

//you can declare an entire row

int[] secondRow = {4, 5, 6};

myMatrix[1] = secondRow;

myMatrix[2][0] = 7;

myMatrix[2][1] = 8;

myMatrix[2][2] = 9;

//if you want to print out each element on a separate line

for (int i = 0 ; i < 3; i++) {

for (int j = 0; j < 3; j++) {

System.out.println(myMatrix[i][j]);

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:-

import java.util.*;
class TDarray{
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int[][] a = new int[3][3];
       for(int i = 0;i<3;i++){
           for(int j = 0;j<3;j++){
               System.out.print("Enter a["+i+"]["+j+"]");
               a[i][j] = sc.nextInt();
           }
       }
       System.out.println("Elements in the matrix:");
       for(int i = 0;i<3;i++){
           for(int j = 0;j<3;j++){
               System.out.print(a[i][j]+" ");
           }
           System.out.println();
       }
   }
}

OUTPUT:-

NOTE:- The question is not clear...Actually you did not tell what to do...so I decided to do what is given in the question...if you have questionn just post it in the comment section...I will send answer for that..   

          THANK YOU!!!!! PLEASE GIVE POSITIVE RATING

Add a comment
Know the answer?
Add Answer to:
In this assignment, we will show you the benefits of test driven development. You will produce...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D...

    Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D arrays in Java. Create a single Java class Matrix and inside the class create the specified static methods as described Task # Description 1 Create a matrix (known components) 2 Create a matrix (random components) 3 Create a matrix from vectors 4 Compare two matrices 5 Add two matrices 6 Subtract two matrices 7 Multiply a matrix by a scalar 8 Multiply two matrices...

  • Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right...

    Hi i need heeeeelllllp on this assignment i need to print the numbers diagonal top right corner to the bottom left corner and i dont know how to do it please help me thank you dd another method to the bottom of the "TwoDimArraysMethods.java" file called "printDiagonalRL()"                                         public static void printDiagonalRL(int[][] matrix) 4. Call this method in the main file ("TwoDimArraysAsParam.java") passing it "board." e.g. TwoDimArraysMethods.printDiagonal(board); 5. Your new method should print any numbers along the diagonal from...

  • Can you help me with this code in Java??? import java.util.Scanner; public class Main { public...

    Can you help me with this code in Java??? import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int rows = 3; int columns = 4; int[][] arr = new int[rows][columns]; for(int i = 0; i < rows; ++i) { for(int j = 0; j < columns; ++j) { System.out.println("Enter a value: "); arr[i][j] = scan.nextInt(); } } System.out.println("The entered matrix:"); for(int i = 0; i < rows; ++i) { for(int j...

  • Use basic java for this after importing PrintWriter object You will make a simple Magic Square...

    Use basic java for this after importing PrintWriter object You will make a simple Magic Square program for this Java Programming Assignment. Carefully read all the instructions before beginning to code. It is also required to turn in your pseudocode or a flowchart along with this program. Here are the instructions: At the beginning of the program, briefly describe to the user what a Magic Square Matrix is (described further on), and then allow them to enter “start” to begin...

  • I have a table that looks like this. 1234 5678 9101112 I need to use this...

    I have a table that looks like this. 1234 5678 9101112 I need to use this code public class Lab8 { public static void main(String argv[]) { int ar[][] = new int[3][4]; int n = 1; for (int i=0; i < ar.length; i++) { for (int j=0; j< ar[i].length; j++) { ar[i][j] = n; n++; } } // print out the elements of the array // left to right, top to bottom for (int i=0; i < ar.length; i++) {...

  • Could you do that in C language? Here is the code which we got #include <stdio.h>...

    Could you do that in C language? Here is the code which we got #include <stdio.h> #define MAX_SIZE 20 // function definitions void displaySpiral(int matrix[][MAX_SIZE], int size); void displayMatrix(int matrix[][MAX_SIZE], int size); int takeInput(int inputMatrix[][MAX_SIZE]); int main() { int matrix[MAX_SIZE][MAX_SIZE]; int matrixSize = takeInput(matrix); printf("Displaying the whole matrix:\n"); fflush(stdout); displayMatrix(matrix, matrixSize); printf("Now, displaying the matrix in a spiral way:\n"); fflush(stdout); displaySpiral(matrix, matrixSize); return 0; } // already implemented for you int takeInput(int inputMatrix[][MAX_SIZE]) { int size; printf("What is the size...

  • Why is my multiplication wrong when i do a matrix of 3 x 5 and 2...

    Why is my multiplication wrong when i do a matrix of 3 x 5 and 2 x 2? code below import java.util.*; public class matrix { public static void main(String[] args) { int m, n, i, j; Random rand = new Random(); Scanner scan = new Scanner(System.in); System.out.print("enter how many rows:"); m = scan.nextInt(); System.out.print("enter how many columns:"); n=scan.nextInt(); int matrix_1[][] = new int[m][n]; //Initialize matrixes int maritx_2[][] = new int[m][n]; int matrix_add[][] = new int[m][n]; int matrix_mul[][] = new...

  • In JAVA Thank You What is the exact output produced by running the method test? /**...

    In JAVA Thank You What is the exact output produced by running the method test? /** * TestSwap.java * Demonstrates parameter passing involving arrays and integers, * scope of variables, flow of control, and overloaded methods. */ public class TestSwap { public void swap (int x, int y) { int temp; temp = x; x = y; y = temp; System.out.println("Inside swap version 1:"); System.out.println("x = " + x); System.out.println("y = " + y); } public void swap (int[] a,...

  • Line number 9 contains the code line that declares the result array ( asked in another...

    Line number 9 contains the code line that declares the result array ( asked in another question of this exam). On Line number 11 where col_ contains the correct statement ( asked in another question of this exam) Question: Write the codeline (single line) to compute the matrix multiplication of "frstMatrix" and "scndMatrix". For this question you will write a code line for line number 17 1 package ok4; 2 //This java program multiplies two matrices 3 //represented with two...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT