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
xz_007 [3.2K]
2 years ago
9

Read one positive integer n. Then create an n X n two-dimensional array and write the code that stores integers from 1 to n2 as

follows. Print the array using System.out.printf statement.
Enter the size of the array : 1 Enter the size of the array : 2
1 1 2
4 3
Enter the size of the array : 10
Enter the size of the array : 7 1 2 3 4 5 6 7 8 9 10
---------------------------------------- 20 19 18 17 16 15 14 13 12 11
---------------------------------------- 21 22 23 24 25 26 27 28 29 30
1 2 3 4 5 6 7 40 39 38 37 36 35 34 33 32 31
14 13 12 11 10 9 8 41 42 43 44 45 46 47 48 49 50
15 16 17 18 19 20 21 60 59 58 57 56 55 54 53 52 51
28 27 26 25 24 23 22 61 62 63 64 65 66 67 68 69 70
29 30 31 32 33 34 35 80 79 78 77 76 75 74 73 72 71
42 41 40 39 38 37 36 81 82 83 84 85 86 87 88 89 90
43 44 45 46 47 48 49 100 99 98 97 96 95 94 93 92 91
Computers and Technology
1 answer:
marysya [2.9K]2 years ago
8 0

Answer:

The program in Java is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

    int n;

    Scanner input = new Scanner(System.in);

 System.out.print("Size of array: ");

 n = input.nextInt();

 int count = 1;

 int[][] arr = new int[n][n];

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

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

         arr[i][j] = count;

         count++;      }  }

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

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

         System.out.printf(arr[i][j]+" ");      }

     System.out.println();  } }}

Explanation:

This declares the size of the array

    int n;

    Scanner input = new Scanner(System.in);

This prompts the user for size of array

 System.out.print("Size of array: ");

This gets input for size of array

 n = input.nextInt();

This initializes the array element to 1

 int count = 1;

This creates a 2d array

 int[][] arr = 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

         arr[i][j] = count;

         count++;      }  }

The following nested loop prints the array elements

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

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

         System.out.printf(arr[i][j]+" ");      }

     System.out.println();  } }}

You might be interested in
1.What is the output of the following program? [10 Marks]namespace ConsoleApp1{class Program{static void Main(string[] args){int
Nataliya [291]

The program outputs the following rectangular array:

0 0 0 0

0 1  2 3

0 2 4 6

0 3 6 9

0 4 8 12

This is the correctly formatted C# program:

namespace ConsoleApp1{

   class Program

   {

       static void Main(string[] args)

       {

           int i, j;    // <em>declare index variables used to iterate over the array A</em>

           int [,] A = new int[5,5];   // <em>create a 5 by 5 array</em>

           

           /*<em> Iterate over the array with the index variables i and j</em>

<em>                and initialize each location A[i, j] with the product </em>

<em>                of i and j.</em> */  

           for (i = 0; i < 5; ++i)

           {

               for (j = 0; j < 4; ++j)

               {

                   A[i, j] = i*j;

               }

           }

           

           /* <em>Iterate over the array again. This time, swap locations </em>

<em>                A[i, j] with A[j, i]</em> */

           for (i = 0; i < 5; ++i)

           {

               for (j = 0; j < 4; ++j)

               {

                   if (i < 5)

                   {

                       A[j, i] = A[i, j];

                   }

                   else

                       break;

                   

                   // <em>display the current location A[i, j]</em>

                   Console.Write(A[i, j] + " ");

                   

               }

               /* <em>print a newline to prepare for the next line of printing</em>

                   <em>which corresponds to the next column i</em> */

               Console.WriteLine();

                // <em>pause and wait for user keypress before continuing</em>

               Console.ReadLine();

               

               }

           }

       }

   }

When executed, this program simply prints a rectangular array like so;

0 0 0 0

0 1  2 3

0 2 4 6

0 3 6 9

0 4 8 12

Learn more about predicting program output here: brainly.com/question/20259194

6 0
2 years ago
I have a Dell laptop and last night it said that it needed to repair it self and asked me to restart it. So I did but every time
olga_2 [115]

The same thing happened with my HP laptop but my dad refresh the laptop before restating it worked

5 0
2 years ago
Point mode allows you to select cells for use in a formula by using your finger or the pointer
Serga [27]
That statement is true

in excel, you could enter point mode by pressing any keyboard navigation such as page down, page up, or the arrow keys or by clicking any cells in the worksheet

This mode will select a cell or range as formula operand


7 0
3 years ago
An example of software is a _____.<br><br> spreadsheet<br> mouse<br> track ball<br> printer
algol13

An example of software is a spreadsheet :)

8 0
2 years ago
Companies typically like to design scorecards that fit their business and industry. As a result there are now software applicati
Leya [2.2K]

Answer:

Web-based balanced scorecard applications are sometimes referred to as performance dashboards.

Explanation:

Performance dashboards are common management tools used to gauge performance and enable business people to measure, monitor, and manage the key activities and processes needed to achieve business goals.

6 0
2 years ago
Other questions:
  • What's a qat on a computer
    12·2 answers
  • What is the danger in judging someone according to his or her social networking profile
    12·1 answer
  • PLZ HELP ME! What is a false statement about online time?
    9·1 answer
  • A(n) _____ is a telephone facility that manages incoming calls, handling them based on the number called and an associated datab
    5·1 answer
  • User can use ______ commands to search for and correct words in a document
    13·1 answer
  • Which is a benefit of using the paste link option?
    15·2 answers
  • Which of the following substances increases in quantity during repititive muscle contraction during oxygen deficti ?
    11·1 answer
  • What are the benefits of building redundancy into a network?
    12·1 answer
  • Please help this is a coding assignment I need help! (use python)
    12·1 answer
  • Choose the response that best completes the following statement.
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!