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
ozzi
3 years ago
10

• Write a method called generateTriangleNumbers(). This method will take in an integer x and will return an array of integers co

ntaining the first x triangle numbers. The nth triangle number is the sum of 1 + 2 + 3 + 4...(n − 1) + n. o generateTriangleNumbers(3) returns the array {1,3,6} o generateTriangleNumber(1) returns the array {1} o generateTriangleNumbers(7) returns the array {1, 3, 6, 10, 15, 21, 28}

Computers and Technology
2 answers:
iris [78.8K]3 years ago
4 0

Answer:

Check the explanation

Explanation:

//GenerateTriangleNumbers.java

import java.util.Arrays;

import java.util.Scanner;

public class GenerateTriangleNumbers {

   public static int[] generateTriangleNumbers(int x){

       int arr[] = new int[x];

       int sum = 0;

       for(int i = 1;i<=x;i++){

           sum += i;

           arr[i-1] = sum;

       }

       return arr;

   }

   public static void main( String [] args ){

       int n;

       Scanner in = new Scanner(System.in);

       System.out.print("Enter n: ");

       n = in.nextInt();

       System.out.println(Arrays.toString(generateTriangleNumbers(n)));

   }

}

Kindly check the attached image below for the code output.

Stolb23 [73]3 years ago
4 0

Answer:

See explaination

Explanation:

/GenerateTriangleNumbers.java

import java.util.Arrays;

import java.util.Scanner;

public class GenerateTriangleNumbers {

public static int[] generateTriangleNumbers(int x){

int arr[] = new int[x];

int sum = 0;

for(int i = 1;i<=x;i++){

sum += i;

arr[i-1] = sum;

}

return arr;

}

public static void main( String [] args ){

int n;

Scanner in = new Scanner(System.in);

System.out.print("Enter n: ");

n = in.nextInt();

System.out.println(Arrays.toString(generateTriangleNumbers(n)));

}

}

You might be interested in
Imagine that you are designing an application where you need to perform the operations Insert, DeleteMaximum, and Delete Minimum
fiasKO [112]

Answer:

A stack data structure should be used. The time complexity of the insert, delete minimum and maximum operation is O(1).

Explanation:

The stack data structure is an indexed structure that holds data in an easily retrievable way. Data is held in a first-in last-out method as elements in the structure are popped out from the end of the stack when retrieved sequentially.

The worst-case time complexity of getting the minimum and maximum elements in a stack and deleting it is O(1), this is also true for inserting elements in the stack data structure.

3 0
3 years ago
Nina is explaining the SQA process to her friend Amanda.
Nezavi [6.7K]
<span>B. Plan
</span><span>C. Planning
yes or no</span>
4 0
3 years ago
What two factors make up the skills of a good typist
Vikki [24]

Answer:

I feel to be a good typist one would have to have a good grasp of reading, grammar, and the ability to make errors to a lesser degree than more so. I can type, myself, 120-150 wpm with an error rate of 0-2. I also have the ability of not having to look at the keyboard as I type, and have a good eye on catching errors.

Explanation:

5 0
3 years ago
Analyzing computer systems to gather potential legal evidence is computer ________
hodyreva [135]
It is called computer forensics.
5 0
3 years ago
The _______ valve protects the air pump from reverse-exhaust pressure.
alexandr402 [8]
D. The answer for this is the gulp
7 0
3 years ago
Other questions:
  • What could break the circuit between your home and an electric power plant?
    15·2 answers
  • Which of the following is the most effective password?
    15·2 answers
  • QUESTION
    14·1 answer
  • Give two reasons you should be aware of your computer's system components and their characteristics.
    10·1 answer
  • An alarm clock draws 0.5 A of current when connected to a 120 volt circuit. Calculate its resistance.
    10·1 answer
  • You have recently subscribed to an online data analytics magazine. You really enjoyed an article and want to share it in the dis
    9·1 answer
  • Do a comment if u hate me.or think im d.U.m b. add a answer if u dont care. thank all the asnwers or report for saying i dont ex
    9·1 answer
  • Take points for free who are new and enjoye them
    9·2 answers
  • Consider a file/directory with the following info:
    14·1 answer
  • bro i got banned for posting an amazing bulk pic, but this dude literally posted an inappropriate, dafuq is wrong with this bann
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!