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
A web-based application encounters all of the connectivity and compatibility problems that typically arise when different hardwa
andrezito [222]

Answer:

False

Explanation:

A web-based application encounters connectivity and compatibility relate to data server. It does not belong to any hardware environments.

A web based application is accessed over network.They run inside a web browser. Small of program is download to user's desktop, but this processing is done over internet.

6 0
3 years ago
Cool fchgjvkugyftdycfhgjkliugytbnhmjku
alexandr1967 [171]

Answer:

the cats face XD

Explanation:

3 0
3 years ago
A network administrator for a small company is contemplating how to scale the network over the next three years to accommodate p
choli [55]

Answer:

Option B,C,E

Explanation:

4 0
3 years ago
Larry sent an email to Andy. Andy didn't open Larry's email but still understood what the message was. How did Andy determine th
Sladkaya [172]

Andy knew what the message was because of the subject you are required to add in almost all email sights.

7 0
3 years ago
The simplest element that exists is only one proton and one electron. It is what stars are made of. It's symbol is "H". What is
lesya [120]

Answer:

Hydrogen.

Explanation:

Hydrogen is the simplest element that exists. The symbol for the chemical element Hydrogen is "H" and it is a colourless, tasteless, odorless, and highly flammable gas.

Hydrogen is a chemical element found in group (1) of the periodic table and as such it has one (1) electrons in its outermost shell. Therefore, Hydrogen has an atomic number of one (1) and a single valence electrons because it has only one proton and one electron in its nucleus.

Additionally, all stars are made up of Hydrogen.

A star is a giant astronomical or celestial object that is comprised of a luminous sphere of plasma, binded together by its own gravitational force. Stars are typically made up of two (2) main hot gas, which are Hydrogen (H) and Helium (He).

6 0
3 years ago
Other questions:
  • For Adults/Adolescents, you should call/activate EMS: Before providing CPR. After providing CPR for 2 minutes. After an AED has
    13·1 answer
  • 30 POINTS PLEASE HURRY<br><br><br> How do you use information technology in your daily life?
    8·1 answer
  • 1.   Which of the following is an example of a primary cost of an accident or injury?
    5·2 answers
  • Which of the following conditions will maximize the amount of interest you earn
    5·1 answer
  • Does Kennesaw State University have any computing ethical policy for computer usage? If so - what is it?
    6·1 answer
  • Which type of security policy is intended to provide a common understandingof the purposes for which an employee can and cannot
    15·1 answer
  • Which of the following should be performed to prove the value of a security awareness training program?
    8·1 answer
  • Question #8
    5·1 answer
  • Type of cable installed on a patch panel?
    15·1 answer
  • What is<br> a an<br> output device
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!