Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Write a program to construct a triangle with the ‘*’

                         

This lesson in Java programming will teach you the coding for constructing a shape of triangle by using '*'. First of all make a class named 'triangle' under the Java I/O package and as we have to use the Buffer class, the application of all try and catch block is important for avoiding any kind of error. After creating BufferedReader object and input stream reader define an integer 'a' and apply parseInt method for the conversion of string into integer. 

Now apply the for loop and define an integer 'i' and it should be either less than or equal to the integer "a" (the input number). Again define another integer type variable "j" in another for loop. Here in the second for loop "j" the number of times we have to print *. 

Now compile and run the program and insert any number on your command window and surely you will get a triangle shape with star *. You can take any other object instead of *. 

Here is the code of the program: 

import java.io.*;

class triangle{
  public static void main(String[] args) {
    try{
      BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
      System.out.println("enter the number");
      int a= Integer.parseInt(object.readLine());
      for (int i=1; i<a;i++ ){
        for (int j=1; j<=i;j++ ){
          System.out.print("*");
        }
        System.out.println("");
      }
    }
    catch(Exception e){}
  }
}

Download the program.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

4 comments so far (
post your own) View All Comments Latest 10 Comments:

prog for * * * *
* * *
* *
*
code for printing the above triangle

Posted by gyanendra on Thursday, 02.28.08 @ 12:57pm | #50391

Dear sir,
could you explain me clearly about the working of for loop for the above example?

Posted by Preetha on Friday, 01.18.08 @ 09:48am | #45494

hay as the program is meant for printing the
no.of. time a star according to the user input
in the loop u got to put equals only then it
give such output otherwise it gives u wrong
for
eg:
if user input is 5 then 4 star prints
so the loop should be (for int i=0;i<=a;i++)

Posted by Gunaranjan on Monday, 12.17.07 @ 09:15am | #42677

prog for * * * *
* * *
* *
*
code for printing the above triangle.

Posted by chinni on Thursday, 10.18.07 @ 18:29pm | #34336

Latest Searches:
finding superscript in
create txt file in spe
text size
Easy UML Diagrams
flex datagrid
adding image in j2ee
program
Scrollbar for JList
Flash Dynamic Content
checkbox button enable
ะà¸??ะà¸?ย ะà
Servlet Context
Hibernate API
Hibernate with DAO
\n java
richfaces a4j taglibr
Insert Data into Datab
Combattons la programm
codebar
tibco
Quartz Tutorial
J2ee
compression of a file
Photoshop Text Effects
Visual Basic Database
load file
how to get applicate s
alignment components
How to create Jasperpr
parseInt
delete
include tag in jsp
display the sum of 20
eclipseme1.7.3 downloa
insert fields blob
jsf set href
Date validation in JSF
binary recursio
17
Array in Java
flex struts
jQuery To Slide Effect
how to use tab control
'string variable in sw
select a row of data t
application context in
MULTIPLE SELECT COMBO
how to capture multipl
3DS MAX Effects Advanc
create funtions in ora
combine integer and st
convert linked list to
tablibrary
what is array.
Updownselect Tag (Form
dynamic insert value J
types of webserver
requestdispatcher in j
update form in java
get url
<ajax:> tag in jstl
swing
java program to find s
Detached criteria
Java Count words,reve
java write file line b
display image in java
program to invoke ejb
PDF Tutorials
how to write in pdf us
input and output speed
Hibernate Min() Functi
Reading File into Byte
write int to file
spring with quartz
jar
square root loop
ั?à¹???ะà¸?ะà¸?à
decimals
ejp
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.