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
Harman [31]
2 years ago
10

Write a piece of code that constructs a jagged two-dimensional array of integers named jagged with five rows and an increasing n

umber of columns in each row, such that the first row has one column, the second row has two, the third has three, and so on. The array elements should have increasing values in top-to-bottom, left-to-right order (also called row-major order). In other words, the array's contents should be the following: 1 2, 3 4, 5, 6 7, 8, 9, 10 11, 12, 13, 14, 15
PROPER OUTPUT: jagged = [[1], [2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14, 15]]
INCORRECT CODE:
int jagged[][] = new int[5][];
for(int i=0; i<5; i++){
jagged[i] = new int[i+1]; // creating number of columns based on current value
for(int j=0, k=i+1; j jagged[i][j] = k;
}
}
System.out.println("Jagged Array elements are: ");
for(int i=0; i for(int j=0; j System.out.print(jagged[i][j]+" ");
}
System.out.println();
}
expected output:jagged = [[1], [2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14, 15]]
current output:
Jagged Array elements are:
1
2 3
3 4 5
....
Computers and Technology
1 answer:
Ksivusya [100]2 years ago
4 0

Answer:

Explanation:

The following code is written in Java and it uses nested for loops to create the array elements and then the same for loops in order to print out the elements in a pyramid-like format as shown in the question. The output of the code can be seen in the attached image below.

class Brainly {

   public static void main(String[] args) {

       int jagged[][] = new int[5][];

       int element = 1;

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

           jagged[i] = new int[i+1]; // creating number of columns based on current value

           for(int x = 0; x < jagged[i].length; x++) {

               jagged[i][x] = element;

               element += 1;

           }

       }

       System.out.println("Jagged Array elements are: ");

       for ( int[] x : jagged) {

           for (int y : x) {

               System.out.print(y + " ");

           }

           System.out.println(' ');

       }

       }

   }

You might be interested in
Help fast plzzzzzzzzzzzz ​
eimsori [14]

Answer:

Which question would you like help with?

4 0
3 years ago
Read 2 more answers
How many passes will it take to find the four in this list?
earnstyle [38]

Answer:

3 is the correct answer

I got correct on my test

7 0
3 years ago
Read 2 more answers
I NEED HELP WITH SOME PROBLEM ON BRAINLY PLEASE HELP
docker41 [41]
What is the issue,please tell me so i can know ur question
6 0
3 years ago
Define power supply and types of power supply<br>​
emmainna [20.7K]

Answer:

hope you like it

Explanation:

Two types of power supplies exist, DC-DC and AC-DC. DC-DC power supplies allow you to plug in electrical devices into car outlets or similar sources that supply direct current, or DC, power. These power supplies are not the most commonly used, though.

Classification of Power Supply and Its Different Types

OUTPUT = DC OUTPUT = AC

INPUT = AC Wall wart Bench power supplies Battery charger Isolation transformer Variable AC supply Frequency changer

INPUT = DC DC-DC converter Inverter Generator UPS

4 0
2 years ago
Which of these is a physical health benefit provided by playing team sports? A. a spiritual connection to others B. lower choles
AfilCa [17]

Answer:

B. lowering cholesterol

Explanation:

Edge 2021, made a 100 on the quiz. Good luck :)

3 0
2 years ago
Read 2 more answers
Other questions:
  • Discuss the differences between dimensionality reduction based on aggregation and dimensionality reduction based on techniques su
    13·1 answer
  • My computer have black spots and line
    7·2 answers
  • A smart phone is always a _____.<br> client<br> server<br> network<br> process
    10·1 answer
  • Testing for information would be most likely to occur in which type of engineering?
    5·2 answers
  • What is the trickiest time of the day to drive? A. Early morning B. Late night C. After the sun sets
    8·2 answers
  • Convert the decimal integer, 353.87510 to each of these forms:
    9·1 answer
  • Which one is not the part of motherboard ?<br>O Registers<br>O<br>Bus<br>O<br>Port<br>O<br>none​
    14·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    6·1 answer
  • Which statement describing the arcade games played in the 1970s is true?
    14·1 answer
  • A natural language processor reads the sentence The walk was tiring and mistakes the noun “walk” as a verb. What is such an erro
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!