triangle shape

triangle shape

Hi,

I have to create a program which its output is:

  1. +
  2. ++
  3. +++
  4. ++++

and this what I did so far :

package symbols; import java.util.*; public class Symbols {

public static void main(String[] args) {
 Scanner read = new Scanner (System.in);
 int nline, count, countl, nspace= 0, i;
 char symbol;
 System.out.print(" how many lines you want to print? ");
 nline= read.nextInt();
 System.out.print("what is the symbol you want to use ");
 symbol= read.next().charAt(0);
 for (countl=1; countl<=nline; countl++){
    System.out.print(symbol);
    System.out.println();
    for (count=1; count<=countl; count++)
        System.out.print(symbol);}
}

}

but this is what I get:

  1. +
  2. ++
  3. +++
  4. ++++
  5. ++++

I don't know why it keep giving me the last line twice !! what is the problem and who can I fix it ?

View Answers

December 8, 2012 at 10:46 AM

Here is a code that creates a triangle of the symbol.

import java.util.*;

 public class Symbols {
     public static void main(String[] args) {
      Scanner read = new Scanner (System.in);
      int nline, count, countl, nspace= 0, i;
      char symbol;
      System.out.print(" how many lines you want to print? ");
      nline= read.nextInt();
      System.out.print("what is the symbol you want to use: ");
      symbol= read.next().charAt(0);
      for (countl=1; countl<=nline; countl++){
        System.out.println();
        for(count=1; count<=countl; count++)
            System.out.print(symbol);
         }
    }
}









Related Tutorials/Questions & Answers:
triangle shape
triangle shape  Hi, I have to create a program which its output is: + ++ +++ ++++ and this what I did so far : package symbols; import java.util.*; public class Symbols { public static void main(String[] args) { Scanner
Java create triangle pattern
Java create triangle pattern In this tutorial, you will learn how to create a triangle shape. For this, user is allowed to enter number of lines to display the triangle of that length and a symbol to show the triangle in a particular
Advertisements
triangle
triangle  how to draw triangle numbers with stars in html with the help of javascript
triangle
the sides of a triangle If they can form a triangle, determine and print if they can also form the sides of a right-angle triangle The class should include proper data
Write a program to construct a triangle with the ?*?
programming will teach you the coding for constructing a shape of triangle by using... a triangle shape with star *. You can take any other object instead of *.  Here... Write a program to construct a triangle
triangle output
triangle output  program to get the following output
Triangle pgm
Triangle pgm  how to write code fa this??? 1 222 33333 4444444 55555555 666666666
pascal triangle
pascal triangle   given string : char str[]="123456789"; write a program in 'c'-language that displays the following: 1 232... the following link:ADS_TO_REPLACE_1 C Pascal's Triangle Thanks
triangle output
triangle output  program to get the following output: * *   Hi Friend, Please specify the pattern properly.ADS_TO_REPLACE_1 Thanks
Triangle program
Triangle program  1 121 12321 1234321 123454321 kindly give... a program for this triangle    1 121 12321 1234321 write a program for this triangle    1 121 12321 1234321 write a program
Code for a triangle.....
Code for a triangle.....   1 1 5 1 1 5 25 5 1 What is the source Code for above output
Triangle problem
Triangle problem  what's the logic for create pattern program how can i create any pattern program with in minute. like this 1 2 5 3 6 8 4 7 9 10
shape looping
shape looping  can some1 help me?i have to make a shape using "*" by looping...and i dun know how...please and thank you * **   java diamond shape: public class Diamond{ public static void main(String[] args){ int
Triangle Program
Triangle Program  i want program code for 1 2 3 4 5 6 7 8 9 10 any body please help me   public class Triangle { public static void main(String[] args
ModuleNotFoundError: No module named 'triangle'
ModuleNotFoundError: No module named 'triangle'  Hi, My Python... 'triangle' How to remove the ModuleNotFoundError: No module named 'triangle... to install padas library. You can install triangle python with following
ModuleNotFoundError: No module named 'shape'
ModuleNotFoundError: No module named 'shape'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'shape' How to remove the ModuleNotFoundError: No module named 'shape'
Golden triangle tours
Golden triangle tours  Hi, Can anyone tell me something about Golden triangle tours? Thanks   Hi, Golden Triangle tour cover Delhi, Agra and Jaipur. Please check India Golden Triangle Tours. Thanks
Golden Triangle Tours
Golden Triangle Tours  What is golden triangle tours ..and how it is related to the Agra and Jaipur and Delhi trip? Please explain me. Thanks
How to convert a picture into a shape, convert a picture into a shape, picture shape
How to convert a picture into a shape       If you want to use a picture shape but you are not able for that, don't worry. You will learn easily to convert a picture into shape. Take
Shape - Java Beginners
Shape  Respected Sir, Please send me the code of diamond shape by using loop and with single statement of " " and single statement with "*".  ... for diamond shape.   Hi friend I understand your problem, so that I
ModuleNotFoundError: No module named 'Pascal_Triangle'
ModuleNotFoundError: No module named 'Pascal_Triangle'  Hi, My... named 'Pascal_Triangle' How to remove the ModuleNotFoundError: No module named 'Pascal_Triangle' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'right-triangle'
ModuleNotFoundError: No module named 'right-triangle'  Hi, My... named 'right-triangle' How to remove the ModuleNotFoundError: No module named 'right-triangle' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Flask-Triangle'
ModuleNotFoundError: No module named 'Flask-Triangle'  Hi, My... named 'Flask-Triangle' How to remove the ModuleNotFoundError: No module named 'Flask-Triangle' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Pascal_Triangle'
ModuleNotFoundError: No module named 'Pascal_Triangle'  Hi, My... named 'Pascal_Triangle' How to remove the ModuleNotFoundError: No module named 'Pascal_Triangle' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'triangle_plot'
ModuleNotFoundError: No module named 'triangle_plot'  Hi, My... 'triangle_plot' How to remove the ModuleNotFoundError: No module named 'triangle_plot' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'dxl-shape'
ModuleNotFoundError: No module named 'dxl-shape'  Hi, My Python... 'dxl-shape' How to remove the ModuleNotFoundError: No module named 'dxl-shape' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'shape-commentator'
ModuleNotFoundError: No module named 'shape-commentator'  Hi, My... named 'shape-commentator' How to remove the ModuleNotFoundError: No module named 'shape-commentator' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'shape-types'
ModuleNotFoundError: No module named 'shape-types'  Hi, My Python... 'shape-types' How to remove the ModuleNotFoundError: No module named 'shape-types' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'dxl-shape'
ModuleNotFoundError: No module named 'dxl-shape'  Hi, My Python... 'dxl-shape' How to remove the ModuleNotFoundError: No module named 'dxl-shape' error? Thanks   Hi, In your python environment you
Version of ca.seinesoftware>xml-shape dependency
List of Version of ca.seinesoftware>xml-shape dependency
how to perform a equqlity triangle in java
how to perform a equqlity triangle in java  below the output 1 2 3 4 6 5 7 9 10 8
How to calculate area of triangle
Area of Triangle       In this section we will learn how to calculate area of triangle. We are going to use area of triangle is half of the area of the parallelogram. Here
Java draw triangle draw method?
Java draw triangle draw method?  hi how would i construct the draw method for an triangle using the 'public void draw (graphics g ) method? im...; Here is an example that draws a triangle using drawPolygon method. import
ModuleNotFoundError: No module named 'spats-shape-seq'
ModuleNotFoundError: No module named 'spats-shape-seq'  Hi, My... named 'spats-shape-seq' How to remove the ModuleNotFoundError: No module named 'spats-shape-seq' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'SWMM-xsections-shape-generator'
ModuleNotFoundError: No module named 'SWMM-xsections-shape-generator' ...: No module named 'SWMM-xsections-shape-generator' How to remove the ModuleNotFoundError: No module named 'SWMM-xsections-shape-generator' error
ModuleNotFoundError: No module named 'esy-osm-shape'
ModuleNotFoundError: No module named 'esy-osm-shape'  Hi, My... 'esy-osm-shape' How to remove the ModuleNotFoundError: No module named 'esy-osm-shape' error? Thanks   Hi, In your python
How to convert new paper into a man shape, convert new paper into a man shape, new paper into a man shape
How to convert new paper into a man shape   ... shape in this example. Take a new picture: Take a news paper picture, choose Polygonal lasso tool (L key) to make selection like a man shape
Version of com.shapesecurity>shape-functional-java dependency
List of Version of com.shapesecurity>shape-functional-java dependency
How to print a equilateral triangle patren with numbers
How to print a equilateral triangle patren with numbers  I figure out how to use for loop to print the triangle but i couldn't get the exact values as this http://im37.gulfup.com/FzrOb.jpg could you please help me
how to perform a equqlity triangle in java
how to perform a equqlity triangle in java  below the output 1 2 3 4 6 5 7 9 10 8   Here is an example of pattern like 1 2 3 4 5 6 7 8 9 10 Example : public class NumberTriangleClass{ public static void
Maven Dependency xml-shape >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of ca.seinesoftware >> xml-shape version1.0.0 in your project
print rectangle triangle with ?*? using loops
print rectangle triangle with ?*? using loops   * * * * * * i want print like this.what is the code?   import java.lang.*; class Traingles { public static void main(String args[]) { for(int i=1;i<=5
C Print Pascal Triangle
C Print Pascal Triangle In this section, you will learn how to display Pascal's triangle. A Pascal's triangle is a geometric arrangement of the binomial coefficients in a triangle.The rows of Pascal's triangle are conventionally
NameError: name 'input_shape' is not defined tensorflow 2.0
NameError: name 'input_shape' is not defined tensorflow 2.0  Hi, I...(Flatten(input_shape(28,28))) it is throwing the following error: NameError: name 'input_shape' is not defined tensorflow 2.0 How to resolve it? Thanks
NameError: name 'input_shape' is not defined tensorflow 2.0
NameError: name 'input_shape' is not defined tensorflow 2.0  Hi, I...(Flatten(input_shape(28,28))) it is throwing the following error: NameError: name 'input_shape' is not defined tensorflow 2.0 How to resolve it? Thanks
NameError: name 'input_shape' is not defined tensorflow 2.0
NameError: name 'input_shape' is not defined tensorflow 2.0  Hi, I...(Flatten(input_shape(28,28))) it is throwing the following error: NameError: name 'input_shape' is not defined tensorflow 2.0 How to resolve it? Thanks
Golden Triangle Tour - Enchanting Golden Triangle Tour
The best part of Golden Triangle Tour is that all these three cities are just four to five hours driving distance from each other
Drawing a Shape in Excel Sheet
Drawing a Shape in Excel Sheet In this section, you will learn how to draw a shape in excel sheets using Apache POI library. Using Apache POI, you can draw a shape with the help of Microsoft Office drawing tools. The top-most shape
Java Program Floyd's Triangle
Java Program Floyd's Triangle In this section you will read about how to write a Java program to print Floyd's triangle. This tutorial is about printing a Floyd's triangle in Java. Here you will learn about all the steps
TRIANGLE OF *S AT THE BOTTOM RIGHT!!! - Java Beginners
TRIANGLE OF *S AT THE BOTTOM RIGHT!!!  My Question is to : "Write a program that inputs one integer m and outputs an m-line high triangle of *'s... to make the triangle at the right side but couldn't do so. Can you please solve

Ads