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]
3 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]3 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
True or false: It can take some time for the labs to load once you click “start lab.”
garik1379 [7]

Answer:

True

Explanation:

It takes time for the labs to start-up to start running normally.

8 0
3 years ago
Spam is _____.
DiKsa [7]

Answer:

any kind of unwanted, unsolicited digital communication that gets sent out in bulk

3 0
2 years ago
Which of the following is not a danger of blogging
Ainat [17]
D. staying connected with an old friend.

4 0
3 years ago
Read 2 more answers
What is the difference between paper size and page margins in Word?
sergij07 [2.7K]

Answer:

Paper size refers to the size of the paper you will be printing your document on, while page margins refer to the outside area of a page that can be made bigger or smaller to fit content.

Launch the Page Setup dialog box from the Page Setup group; in the Margins section, enter the page margin values and click OK.

All the statements are correct.

Right-click and add to dictionary

Type the words onto the first page of the document, and click on the Header button to repeat it on all of the other pages

pictures shapes and clipart

none of the above

Explanation:

7 0
3 years ago
Why are rules required for a number system to be useful?
evablogger [386]

Answer

This is because without them no one would know how much each symbol represents, and no one would be able to decipher the message.

Explanation

Number system is a way to represent numbers. It  is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.

In computing or in a computer number systems are the techniques which represents numbers in the computer system architecture where   every value that you are saving or getting into/from computer memory has a defined number system.Computer architecture supports  . Binary number system,Octal number system and Decimal number system.

5 0
3 years ago
Read 2 more answers
Other questions:
  • A series of inventions led to the creation of the electronic digital computer shortly after this war..
    12·1 answer
  • What is the lowest layer of the osi model at which wired and wireless transmissions share the same protocols?
    11·1 answer
  • What software development model focuses on improving the product in small steps each time through the cycle?
    14·2 answers
  • Which of the following are true about the PUSH instruction?
    9·1 answer
  • What kind of device is hardware capable of transferring items from computers t and devices to trans?
    5·1 answer
  • Which of the following is true regarding packaged software and custom software? Group of answer choices Packaged software are ap
    13·1 answer
  • One of your clients is looking into investing in direct participation programs. He is examining several different types of progr
    13·1 answer
  • When you see this traffic signal is turned on, you may _____________________.
    5·2 answers
  • Discuss TWO changes in ICMP that took place with the development of IPV6 and indicate why those changes were made.
    7·1 answer
  • OCR Airlines allows passengers to carry up to 25kg of luggage free of charge. Any additional luggage is charged at £10 per kg. N
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!