Knowee
Questions
Features
Study Tools

For this solution make sure you change the formatting on your answer to "Preformatted".  We will NOT be grading you on formatting, but it will make the grader's life easier.Copy the skeleton of code below into your answer.  Then in the space indicated, add your own code to prompt the user for a number.  If the number is greater than 0 it should print a triangle of that size as shown below.  If the number is less than or equal to 0 it should print nothing.  See the transcripts below for some sample runs of this code:   Enter a number: 3******A second run of this program with different input might look like this:Enter a number: 5***************A third run of this program with a zero or negative input might look like this:Enter a number: -12Use the skeleton of the main method below to write your code.public static void main(String[] args) { Scanner input = new Scanner(System.in);    // TODO: Your code below this line input.close();}

Question

For this solution make sure you change the formatting on your answer to "Preformatted".  We will NOT be grading you on formatting, but it will make the grader's life easier.Copy the skeleton of code below into your answer.  Then in the space indicated, add your own code to prompt the user for a number.  If the number is greater than 0 it should print a triangle of that size as shown below.  If the number is less than or equal to 0 it should print nothing.  See the transcripts below for some sample runs of this code:   Enter a number: 3A second run of this program with different input might look like this:Enter a number: 5*********A third run of this program with a zero or negative input might look like this:Enter a number: -12Use the skeleton of the main method below to write your code.public static void main(String[] args) { Scanner input = new Scanner(System.in);    // TODO: Your code below this line input.close();}

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the code you requested:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        
        // TODO: Your code below this line
        System.out.print("Enter a number: ");
        int num = input.nextInt();
        
        if (num > 0) {
            for (int i = 0; i < num; i++) {
                for (int j = 0; j <= i; j++) {
                    System.out.print("*");
                }
                System.out.println();
            }
        }
        
        input.close();
    }
}

This code first prompts the user to enter a number. If the number is greater than 0, it prints a triangle of asterisks of the size entered by the user. If the number is less than or equal to 0, it does not print anything.

This problem has been solved

Similar Questions

Write code that allow the user to input a number. Use for loop to print the number and 4 numbers after this number the user. For example, if the input is 5, then the program should print:

Write a program that takes a number 𝑁N as the input, and prints it to the output.Input FormatThe only line of input contains a single integer.Output FormatOutput the answer in a single line.Constraints0≤𝑁≤1050≤N≤10 5 Sample 1:InputOutput123123

Choose the correct answer What will be the output of the following? print(33 == 33.0) Options True False 1 0

This code will be used to round a decimal number between 0 and 1 to the nearest whole number. Two lines of code are missing.start input number  display answerendWhich option should go into the box to complete the code

You are given an integer , you have to convert it into a string.Please complete the partially completed code in the editor. If your code successfully converts into a string the code will print "Good job". Otherwise it will print "Wrong answer". can range between to inclusive.Sample Input 0100Sample Output 0Good job

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.