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
Pls help brainliest
Anastasy [175]

the answer to the question is c. i hope this helps.

3 0
3 years ago
Where do we draw the line between creativity and deception?
BARSIC [14]

Answer:

when you are manipulating the pictures for art and creativity purposes and not for changing your own or others appearance.

4 0
3 years ago
IP ______ occurs when an intruder computer fools a network into believing its IP address is associated with a trusted source.
Veseljchak [2.6K]

Answer:

Spoofing

Explanation:

Spoofing that occurs when an intruder computer fools network into believing its IP address is associated with trusted source

5 0
2 years ago
Steven is in a meeting and he is sharing a graph on his monitor with fifty other people. So that the others do not need to crowd
nevsk [136]
The answer is D) Projector because with a projector, its in the name project so it can anything u put on their, and put it on a virtual screen that can be put on a wall, so everyone can see.
8 0
3 years ago
Approximately what percentage of the world population owns a smartphone?
Usimov [2.4K]
The number of smartphone users is forcast to grow from 2.1 billion in 2016 to around 2.5 billion in 2019, with smartphone penetration rates increasing as well.over 36% of the worlds population is projected to use a smartphone by 2018, thats up from about 10% in 2011
5 0
3 years ago
Other questions:
  • What is ucspi-tcp pakage in qmail??
    5·1 answer
  • A(n) __________ describes a set of well-defined logical steps that must be taken to perform a task
    5·1 answer
  • (10 points) A stopwatch has three states named Zero, Running, and Stopped. There are two buttons, named B1 and B2. For each butt
    13·1 answer
  • Drag each tile to the correct box.
    12·1 answer
  • What is one pass of a coding sequence called?​
    13·2 answers
  • A bastion host allows the firewall to connect to the internal network and the perimeter network.TrueFalse
    15·1 answer
  • PLEASE SOMEONE ANSWER THIS
    14·2 answers
  • Explain the characteristics of a first generation computer​
    8·1 answer
  • Analyze the error in the html code :<br><br> HTML
    9·1 answer
  • ________ helps in determining the cause of a security threat in an incident response plan. Question 7 options: A) Restricting sy
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!