print a rectangle

print a rectangle

View Answers

January 13, 2009 at 12:04 AM

Hi friend,

I am sending running code.


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();
}
}
}
}
-----------------------------------------

Thanks

Amardeep









Related Tutorials/Questions & Answers:
print rectangle pattern in java
print rectangle pattern in java  * * * * * * * how to generate this pattern in java??   Hi friend try this code may this will helpful for you public class PrintRectangle { public static void main
print a rectangle - Java Beginners
print a rectangle  how do I print a rectangleof stars in java using simple while loop?Assuming that the length n width of the rectangle is given.  Hi friend, I am sending running code. import java.io.
Advertisements
print rectangle triangle with ?*? using loops
print rectangle triangle with ?*? using loops   * * * * * * i want print like this.what is the code?   import java.lang....("*"); } } System.out.print(" "); } } print("code sample");   class
Rectangle
Rectangle  Could anybody help me on this problem, Write two Rectangle objects with the following properties: Rectangle1: Height 15 width 53 Y 25 X 15 Rectangle2: height 47 Width 60 Y 12 X 0 It's to be used four-argument
print
print  How to print JFrame All Componant?   Please visit the following link: http://www.roseindia.net/java/example/java/swing/Print.shtml
Print
into the stream and, as opposed to print() method, gets you to the new line after the text
ModuleNotFoundError: No module named 'rectangle'
ModuleNotFoundError: No module named 'rectangle'  Hi, My Python... 'rectangle' How to remove the ModuleNotFoundError: No module named 'rectangle' error? Thanks   Hi, In your python environment you
plotting of points inside a rectangle
plotting of points inside a rectangle  I want to plot various points inside a rectangle such that any two points are at a distance of at least 3... example ,if I have a Rectangle of 20m by 14m then one possible placement of points
ModuleNotFoundError: No module named 'rectangle-packer'
ModuleNotFoundError: No module named 'rectangle-packer'  Hi, My... named 'rectangle-packer' How to remove the ModuleNotFoundError: No module named 'rectangle-packer' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'rectangle-overlap'
ModuleNotFoundError: No module named 'rectangle-overlap'  Hi, My... named 'rectangle-overlap' How to remove the ModuleNotFoundError: No module named 'rectangle-overlap' error? Thanks   Hi, In your
By using Applet display a circle in a rectangle
By using Applet display a circle in a rectangle  Write a java applet to display a circle in a rectangle
How to calculate area of rectangle
How to Calculate Area of Rectangle   ... of rectangle. The area of rectangle is specifies an area in a coordinate space that is enclosed by the rectangle object. In the program coordinate of space its
drawing rectangle in java/Creating a draw rectangle filled with black color function in Java for a grid
drawing rectangle in java/Creating a draw rectangle filled with black color function in Java for a grid  drawing rectangle in java/Creating a draw rectangle (filled with black color) function in Java for a grid
Java gui program for drawing rectangle and circle
Java gui program for drawing rectangle and circle   how to write java gui program for drawing rectangle and circle? there shoud be circle and rectangle button, check box for bold and italic, and radio button red,green and blue
ModuleNotFoundError: No module named 'print_print'
ModuleNotFoundError: No module named 'print_print'  Hi, My Python... 'print_print' How to remove the ModuleNotFoundError: No module named 'print_print' error? Thanks   Hi, In your python environment
Rectangle Canvas MIDlet Example
Rectangle Canvas MIDlet Example   ... of rectangle in J2ME. We have created CanvasRectangle class in this example that extends to the Canvas class to draw the given types of rectangle. In this figure
print a form of *
print a form of *   * *** ***** ******* ********* ******* ***** *** *   Post the format properly
Print Button
Print Button  i want the source code for printing details of jform.. so plz help me for source code of print button
print the newline
print the newline  Why doesn?t the following code print the newline properly? <?php $str = ?Hello, there.\nHow are you?\nThanks for visiting.?; print $str; ?>   Hi friends, Inside the single quotes \n (newline
Draw Ellipse in Rectangle
Draw Ellipse in Rectangle     ... the rectangle. To draw an Ellipse inside the rectangle, we have defined two classes... a rectangle and a circle respectively. ADS_TO_REPLACE_1 By using draw() method
print numbers
print numbers  1234 123 12 1234   1234 123 12 1234
Print the document
Print the document  I tried to print web page.I am using the below...() { var printWindow = window.open('test', 'Print Window', 'height=600,width...;Print Window</title>'); printWindow.document.write('</head>
Print the document
Print the document  I tried to print web page.I am using the below...() { var printWindow = window.open('test', 'Print Window', 'height=600,width...;Print Window</title>'); printWindow.document.write('</head>
How to design a foot print on the sand, print on the sand, print
How to design a foot print on the sand       You might have seen foot prints on the sand field. Do you... Selection: Select Rectangle marquee tool (M key) and make selection as given
Print a statement
Print a statement  hello what would we output for this statement System.out.println ("5"+"A" + 3);   helloADS_TO_REPLACE_1 output will be 5A3
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012
print the sequence
print the sequence  how can I write the code by using for loop to produce this following statement: 10,9,8,7,6,5,4,3,2,1,buzz! please, help me
Program to draw rectangle on each mouse click and erase priviouse rectangles
Program to draw rectangle on each mouse click and erase priviouse rectangles  Program to draw rectangle on each mouse click and erase previous rectangle on next mouse click
diamond print
diamond print   print the pattern 1 2 3 4 5 6 7 8 9 10 11 12
print initials
print initials  How to print initials of a name without using arrays?   Hi Friend, You can try the following code:ADS_TO_REPLACE_1 import java.util.*; public class InitialName { public static void main(String
How to make a Rectangle type pdf
How to make a Rectangle type pdf   ... make a pdf file in the rectangle shape irrespective of the fact whether... is created and it is of type rectangle. The code of the program is given below
J2ME Draw Triangle, Rectangle, Arc, Line Round Rectangle Example
J2ME Draw Triangle, Rectangle, Arc, Line Round Rectangle Example... tutorial, we are going to describe how to draw a triangle, rectangle, arc, line or a round rectangle in one small application. Although we have already explained
Rectangle Image in Java
Rectangle Image in Java       Introduction In this section, you will learn how to create rectangle... , rectangle Drawing , curve drawing and Circle. All types of Geometry classes parts
To print initials
To print initials  import java.util.Scanner; class initials { String a ; int e ; char f ; int b ; int c ; char d; Scanner sc = new Scanner(System.in); void main
Print command
Print command  Can I use System.out.println command in Struts form bean or Struts action class. I am using Struts 1.3.8 but when I write this command. It does not work. Please reply me as soon as possible. Thanks.   
Java Swing: Draw rectangle on mouse click
Java Swing: Draw rectangle on mouse click In this tutorial, you will learn how to draw a rectangle on mouse click. Sometimes, there is a need of mouse clicks.... In the given example, we are going to draw a rectangle by clicking the mouse
should print in console
should print in console  
print form information when click on print button
print form information when click on print button   Sir,I desingn institute webside using jsp and strut by using platform netbean 7.2.So request you please help for printing form information by clickin print button after submit
how to print the server time
how to print the server time  how to print the server time in jsp and update time in fix interval
echo and print statement
echo and print statement  hello, What is the difference between echo and print statement
print square of any number
print square of any number  using c++ language, write aprogram to print the square of any number entered by the user
print without newline in python
print without newline in python  Hi, I have a Python program... the print it in one line. My example: print("I ") print("Love ") print("Python") But the output is coming in new lines. I want to know how to print without
print without newline in python
print without newline in python  Hi, I have a Python program... the print it in one line. My example:ADS_TO_REPLACE_1 print("I ") print("Love ") print("Python") But the output is coming in new lines. I want to know how
ModuleNotFoundError: No module named 'print'
ModuleNotFoundError: No module named 'print'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'print' How to remove the ModuleNotFoundError: No module named 'print'
ModuleNotFoundError: No module named 'print_it'
ModuleNotFoundError: No module named 'print_it'  Hi, My Python... 'print_it' How to remove the ModuleNotFoundError: No module named 'print... to install padas library. You can install print_it python with following
How to print this Format exactly?
How to print this Format exactly?   * * * & reverse
Print the following format
Print the following format  how to print the following format given string "00401121" in java 0-** 1-* 2-* 3- 4
echo and print statement
echo and print statement  hello, What is the difference between echo and print statement?   hii,ADS_TO_REPLACE_1 echo() can take multiple expressions, Print() cannot take multiple expressions. And echo is a little
print variable in iphone
print variable in iphone  how can i print a variable in iphone????   hello,, if you want to print a variable in objective CADS_TO_REPLACE_1 if integer then int i=3; NSLog(@"%d",i);ADS_TO_REPLACE_2 if string

Ads