1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ivanshal [37]
3 years ago
13

Write a program, TwoDimentionalGrid. Ask the user to enter the size of the 2 dimensional array. Here we are not doing any input

validation. We are assuming, user is going to enter a number greater than 1. Create a 2D array with the same row and column number. Now print the array as a number grid starting at 1. Example: At place row number 3 and column number 2, number would be 6 (3*2). Any number would be the product of it's row number and column number. Hint: Use setw 5. Expected Output: Here I am attaching 2 expected output. Make sure your code is running for both input.
Computers and Technology
1 answer:
Nitella [24]3 years ago
4 0

Answer:

The program in Java is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 System.out.print("Array size: ");

 int n = input.nextInt();

 int[][] myarray = new int[n][n];

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

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

         myarray[i][j] = i * j;      }  }

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

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

         System.out.print(myarray[i][j]+" ");      }

     System.out.println();  }

}}

Explanation:

This prompts the user for the array size

 System.out.print("Array size: ");

This gets input for the array size

 int n = input.nextInt();

This declares the array

 int[][] myarray = new int[n][n];

This iterates through the rows

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

This iterates through the columns

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

This populates the array by multiplying the row and column

         myarray[i][j] = i * j;      }  }

This iterates through the rows

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

This iterates through the columns

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

This prints each array element

        System.out.print(myarray[i][j]+" ");      }

This prints a new line at the end of each row

     System.out.println();  }

}

You might be interested in
What type of devices are the keyboard and the mouse?
Angelina_Jolie [31]
 A keyboard is the primary device to enter text that consists of alphabet keys, numeric keys and other specialized keys. a mouse may include one or more buttons and a scroll wheel and works by moving across a smooth surface to signal movement of the pointer. Both are plug and play( PnP).
6 0
3 years ago
Read 2 more answers
2. (40 POINTS) Assume a 16-word direct mapped cache with b=1 word is given. Also assume that a program running on a computer wit
Fynjy0 [20]

Answer:

See the attached file for the answer.

Explanation:

(a) Find attached of question a.

b. the miss rate for the above instructions address sequence is 100% as no address is repeated.

5 0
3 years ago
Xxx<br>uuuuuu<br>uuuu<br>jjnmn<br>jjh
Leviafan [203]
Answer: What’s this??
7 0
3 years ago
QUICK PLZZZZZZZ Which one of the following is considered a peripheral? A Software B Mouse C USB connector D Motherboard
il63 [147K]

A MOUSE is considered a peripheral. A peripheral device connects to a computer system to add functionality.

6 0
3 years ago
Regarding k-NN algorithm which of the following statements is true?
Contact [7]

Answer:

A

Explanation:

KNN could be used for both classification and regression problems

3 0
2 years ago
Other questions:
  • Fractures in Earth’s crust where displacement has occurred are called
    13·1 answer
  • What prefix describes a mass that is 1000 times smaller than a gram
    5·2 answers
  • Consider a system running 10 I/O-bound processes and 2 CPU-bound process. Assume that the I/O-bound processes issue an I/O opera
    9·1 answer
  • What are the coordinates of the origin point? (Select the best answer.)
    10·1 answer
  • Which of the following is a proper use of the application, netstumbler
    9·2 answers
  • 3. Fire and police protection is the main responsibility of
    15·2 answers
  • Which of the following is not a Nintendo game character?
    6·2 answers
  • Jason is working on a Microsoft Excel worksheet and he wants to create a Print Preview shortcut. His teacher asks him to access
    9·1 answer
  • The physical layer of the OSI model is not foundational to any of the other layers. True or False
    8·1 answer
  • How to delete brackets in string java.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!