Question

PLEASE READ THE FULL INSTRUCTION.

Write a Java programme to print the pattern of asterisks shown below. For i=1 For i=2 * * For i=3 For i=n ** * ** ** ........

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;
public class Lab6_Task2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter value for n: ");
        int n = scan.nextInt();
        for(int i = 1;i<=n;i++){
            System.out.println("For i="+i);
            for(int k = 0;k<i;k++) {
                for (int j = 0; j <= k; j++) {
                    System.out.print("* ");
                }
                System.out.println();
            }
        }
    }
}

Output

Enter value for n: 5 For i-1 For i=2 For i=3 For i 4 For i-5

Add a comment
Know the answer?
Add Answer to:
PLEASE READ THE FULL INSTRUCTION. Write a Java programme to print the pattern of asterisks shown...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Develop a complete java program that produces a square pattern of asterisks and spaces. First prompt...

    Develop a complete java program that produces a square pattern of asterisks and spaces. First prompt the user for the size of the pattern, then use for loops to print out the pattern. If the user enters a value that is not a number your program's behavior is arbitrary. For non-positive values your program should print nothing and end normally. Your program should work for input values up to the width of the terminal window. Examples for the first 6...

  • Write an efficient java program to implement BST. Your java program should read n words and...

    Write an efficient java program to implement BST. Your java program should read n words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in engtofren.java file To compile: javac engtofren.java To execute: java engtofren< any data file name Your main method should be as follow: public static void main(String args[]) { engtofren bst = new engtofren (); // try{...

  • Could you guys write an efficient java program to implement BST. Your java program should read...

    Could you guys write an efficient java program to implement BST. Your java program should read words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in xxxxx5.java file (5th java project), where xxxxx is the first 5 characters of your last name. To compile: javac xxxxx5.java To execute: java xxxxx5 < any data file name Your main method should...

  • In Java We want to print the character “*” as the following pattern. For example, for...

    In Java We want to print the character “*” as the following pattern. For example, for n = 5, we have a 5*5 square in the middle and then for 5 rows and columns no character is printed and then then boundary is created using the 5 asterisks. Write a function that gets the odd number input argument n and creates the pattern above. Test your program with n = 3 and 5. Your code for this problem -- Copy...

  • Write a small program that asks the user how many asterisks it should print out. The...

    Write a small program that asks the user how many asterisks it should print out. The user responds with a number, then the program prints that number of asterisks. The number of asterisks to print should be stored in a variable. Finally the program asks the user if it should start over, and repeats as many times as the user wants. The prompt to run the program again should look like the one below, and should wait at the end...

  • JAVA: Write a program that prints a rectangle with a border of asterisks (*). Prompt the...

    JAVA: Write a program that prints a rectangle with a border of asterisks (*). Prompt the user for the width and height of the rectangle. For example: Enter the width and the height of our box. 3 5 *** * * * * * * *** import java.util.Scanner; public class DrawBox { public static void main(String[] args) { Scanner in = new Scanner(System.in);        System.out.println("Enter the width and the height of our box."); /* Type your code here. */...

  • Write a Java program that: 1. Decide on a list of n favorites (songs, bands, movies,...

    Write a Java program that: 1. Decide on a list of n favorites (songs, bands, movies, video games, etc.) (between 5 and 10 favorites is fine). 2. Write a program that lists the n favorites but with a small twist. 3. Read in a file of n favorites (sample file in the Resources/Sample File area)...Please make your own. 4. Print a list of all n favorites to the user (so they know what is coming) 5. Ask if the user...

  • Today you are to write a Java program that will prompt for and read 2 words...

    Today you are to write a Java program that will prompt for and read 2 words of equal length entered by the user, and create a new word which contains the last letter of the 1st word, the last letter of the 2nd word, followed by the second to last character of the 1st word, followed by the second to last character of the 2nd word and so on. Be sure to use the same format and wording as in...

  • MATLAB Write segment of code using nested for loops to print out the following pattern. Your...

    MATLAB Write segment of code using nested for loops to print out the following pattern. Your segments of code should prompt the user for a positive integer, n, and print the following star pattern depending on n. An equilateral triangle. Pictured below is case n = 6. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *...

  • In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this...

    In Jgrasp(Java) Thanks! This solution must use methods. It is recommended to use methods for this solution. Write a program that reads an integer and displays, using asterisks, a filled and hollow square, placed next to each other. For example, if the side length is 5. the program should display: ***** ***** You can assume that the user will enter a side length that is at least 2. If user enters a number smaller than 2, and your program has...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT