Question

Write java program to print the following shape N lines. * * * * * *...

Write java program to print the following shape N lines.

*

* *

* * *

* * * *

* * * * *

* * * * * *

Input: N

Output: The printed shape

Homework Answers

Answer #1
/**
 * @fileName Shape.java
 * @author 
 * @since 21/3/17
 */


import java.util.Scanner;

public class Shape {

    public static void main(String[] args) {
        //creating Scanner object to read input from keyboard
        Scanner console = new Scanner(System.in);
        System.out.print("Enter N:");

        int N = console.nextInt(); //store the user input in variable N
        for(int i=1;i<=N;i++){ 

            for(int j=1;j<=i;j++){
                System.out.print("*");
            }
            System.out.println();
        }

    }
}

output:

Know the answer?
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
Similar Questions
Write a java program that reads two sentences as strings, the program should print the common...
Write a java program that reads two sentences as strings, the program should print the common terms in both sentences example: input: I did my java homework yesterday yesterday i went to java island
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
Write a program to do the following. JAVA CODE • Input an integer n. • Create...
Write a program to do the following. JAVA CODE • Input an integer n. • Create a BinarySearchTree S inserting the keys 1, 2, . . . , n in that order, which will result in a completely-skewed tree. • Measure the time to search for n + 1 in S. 4 • Display the time taken for search.
Write a Java program to print the result of the following operations. Your program should contain...
Write a Java program to print the result of the following operations. Your program should contain 4 methods (for each of given data sets). Yes, methods here are not structurally necessary, this requirement is only for you to get practice writing methods. Test Data: a. -8 + 4.0 * 6 b. (11+9) % 9 c. 20 + (-3)*3.0 / 8 d. 5 + 14 / 3 * 2 - 7 % 3 Your program:
In java : Write a program that will provide important statistics for the grades in a...
In java : Write a program that will provide important statistics for the grades in a class. The program will utilize a for-loop to read ten floating-point grades from user input. Include code to prevent an endless loop. Ask the user to enter the values, then print the following data: Average Maximum Minimum
Write a JAVA program for the following scenario. Given an n × n × n cube...
Write a JAVA program for the following scenario. Given an n × n × n cube containing n3 cells. PLEASE NOTE THAT THIS BOARD HAS 3 DIMENSIONS. We are to place n queens in the cube so that no two queens challenge each other (so that no two queens are in the same row, column, or diagonal). In JAVA, implement it on your system to solve problem instances in which n = 4 and n = 8.
In JAVA Write a RECURSIVE method that receives as a parameter an integer named n. The...
In JAVA Write a RECURSIVE method that receives as a parameter an integer named n. The method will output n # of lines of stars. For example, the first line will have one star, the second line will have two stars, and so on. The line number n will have "n" number of ****** (stars) so if n is 3 it would print * ** *** The method must not have any loops!
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads a string from the keyboard. If the length of the string is an even number, your program should split the string into two strings of equal length. If the length of the string is odd, your program should split the string into two strings where the first part has one more character than the second part. Your program should output the two strings it...
Question: Write any java program. Your Program must include loops, decision structures, input and output, comments.
Question: Write any java program. Your Program must include loops, decision structures, input and output, comments.
Write Java program Lab42.java which takes as input two positive integers m and n and computes...
Write Java program Lab42.java which takes as input two positive integers m and n and computes their least common multiple by calling method lcm(m,n), which in turn calls recursive method gcd(m,n) computing the greatest common divisor of m and n. Recall, that lcm(m,n) can be defined as quotient of m * n and gcd(m,n).
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT