Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN JAVA: D My Account l Central Mi 1 e Chegg Study I Guided S- \\G ?centralLinkl

ID: 3738702 • Letter: I

Question

IN JAVA:

D My Account l Central Mi 1 e Chegg Study I Guided S- G ?centralLinkl Central Mi h.jsp?course assessment id- 22568/ 18course id 1408 18content id-5632809 18step null / Take Test: Activity 1 ÍA- x x CSecure https://blackboardcmich.edu/webapps/assess p Home| Central Michi Zy Central Michigan Ui Y Fantasy Reatll 21 C Home | Chogg.com T T T T Paragraph Arial T Paragraph 3 (12pt) ?·-·-. T-z-e HTHL ESS Path: p Words:0 QUESTION 6 2 points Save Answer Write a program named SeriesUp.java to ask user to enter an integer n, then create an array with the pattem (1, 1, 2,1, 2, 3 1, 2, 3.. n) (spaces added to show the grouping). Note that , … 3 + n, which is known to be exactly n*(n 1)12 the length of the array will be 12 Print the array after generating. Sample interaction: Please enter an integer 6 The series-up array is: 1 1 2 1 2 3 1 2 3 4 1 2 3 451 2 3 4 5 6 Attach File Browse My Computer O Type here to search 11:16 AM E 3/2Ty2018 2

Explanation / Answer

SeriesUp.java

import java.util.Scanner;

public class SeriesUp {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Please enter an integer:");

int n = scan.nextInt();

int size = 0;

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

size+=i;

}

int a[] = new int[size];

for(int i=1,k=0;i<=n;i++) {

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

a[k++]=j;

}

}

System.out.println("The series-up array is:");

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

System.out.print(a[i]+" ");

}

System.out.println();

}

}

Output:

Please enter an integer:
6
The series-up array is:
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6