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

IN JAVA: D CentralLink I central Mic x(New Tab x/ Take Test: Lab g-For L001 C Se

ID: 3730399 • Letter: I

Question

IN JAVA:

D CentralLink I central Mic x(New Tab x/ Take Test: Lab g-For L001 C Secure https://black oardcmich.edu webapps assessmen take launch sp?course assessment id= 225021 1&course; id= 14088/ 1&content; id= 5601843 18 step-null ::: Apps Home! Central Mich zydentral Michigan Ur Fantasy Fontbll 201 e Home IChegg.com Hrowse My Compirer 3 points QUESTION 2 Create a program to ask user for an integer number and then draw a triangle with that size. You may construct a while or do-while loop to allow user enter number repeatedly. Draw a triange for each number entered. Terminate the program if user enter a non-positive number. Simulate the tollowing interaction. Please enter an integer number to draw a triangle Save Answer Enter non-positive number to quit: 10 Name your program Triangle and submit Triangle java Attach Flle Browse ly Computer QUESTION 3 O Type here to search 11:10 AM 3/15/2018

Explanation / Answer

import java.util.Scanner;

class Main {
public static void main(String[] args)
{
// FOR INPUT
Scanner sc = new Scanner(System.in);
int n;
  
// prompting
System.out.println("Enter non-positive number to quit:");
while(true)
{
// taking user input
n = sc.nextInt();
  
// condition to continue
if(n>0)
{
// for number of lines
for(int i=1; i<=n;i++)
{
// for stars in each line
for(int j=1; j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
else
break;
}
}
}

/* SAMPLE OUTPUT

Enter non-positive number to quit:
1
*
3
*
**
***
10
*
**
***
****
*****
******
*******
********
*********
**********
0

*/