Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners RASTER TRAINGLES!!!
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


jas
RASTER TRAINGLES!!!
1 Answer(s)      6 years and a month ago
Posted in : Java Beginners



Advertisement
View Answers

October 27, 2008 at 5:58 PM


Hi friend,


import java.io.*;

public class TrianglesDemo{
final static int WIDTH = 10;
public static void main(String[] param) throws IOException{
InputStreamReader m = new InputStreamReader(System.in);
BufferedReader n = new BufferedReader(m);
System.out.print("Give me the size of each triangle : ");
int size = Integer.parseInt(n.readLine());
System.out.print("The number of triangles you want to output in each row : ");
int noOfTriangles = Integer.parseInt(n.readLine());
System.out.print("The number of rows of triangles you want to output : ");
int noOfRows = Integer.parseInt(n.readLine());
raster(size, noOfTriangles, noOfRows);
}

public static void raster(int a, int b, int c){
String result = "";

for(int Rows=1; Rows<=c; Rows++){
for(int triangles=1; triangles<=b; triangles++){

for (int Size = 1; Size <= WIDTH; Size++) {
for (int j = 1; j <= WIDTH -Size; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2*Size - 1; j++) {
System.out.print("*");
}
System.out.println();
}
System.out.println();
}
}
}
}


----------------------------------------

Visit for more information.

http://www.roseindia.net/java/

Thanks.


Related Tutorials/Questions & Answers:
 

 

 

DMCA.com