473,503 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with rectangle program!

2 New Member
I'm assigned to create a rectangle with inputs of height and width using the drawLine method and loops using asterisks(*).

I've done this without methods on a triangle, but I can't figure this one out.

Please help! thanks
Oct 4 '07 #1
4 5717
JosAH
11,448 Recognized Expert MVP
Can we please see your code (not methods) dealing with triangles?

kind regards,

Jos
Oct 4 '07 #2
Carsomyr
2 New Member
Actually, I have the code for a square program that does similar to the same thing.

Rectangle is more confusing because I need to get 2 inputs, height and width, and determine the rectangle from there, which I'm stuck at, if someone can check out the square code and figure something out for a rectangle. Here it is..


Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. /**********************************************
  4. *                          *
  5. * Prints a square of size                     *
  6. * given by the user.                  *
  7. * Uses the drawLine() method.              *
  8. *                          *
  9. **********************************************/
  10.  
  11. public class Square {
  12.  
  13.     public static void main(String[] args) {
  14.  
  15.     int squareSize;
  16.  
  17.     do {
  18.  
  19.         squareSize = getSquareSize();
  20.         drawSquare(squareSize);
  21.         System.out.println();
  22.  
  23.     } while (squareSize >= 0);
  24.  
  25.     }
  26.  
  27.     /*
  28.      * Prompts user to input number
  29.      * returns input as size of square to print
  30.      */
  31.     public static int getSquareSize() {
  32.  
  33.     int squareInput;
  34.     Scanner myScanner = new Scanner(System.in);
  35.     System.out.print("Enter square size (negative to exit): ");
  36.     squareInput = myScanner.nextInt();
  37.  
  38.     return squareInput;
  39.  
  40.     }
  41.  
  42.     /*
  43.      * Prints a square of given size
  44.      */
  45.     public static void drawSquare(int size) {
  46.  
  47.     for (int i=1; i<=size; i++) {
  48.  
  49.         drawLine(size);
  50.         System.out.println();
  51.  
  52.     }
  53.  
  54.     }
  55.  
  56.     /*
  57.      * Prints a line of given length
  58.      */
  59.     public static void drawLine(int length) {
  60.  
  61.     for (int i=1; i<=length; i++)
  62.         System.out.print("*");
  63.  
  64.     }
  65.  
  66. }
Oct 5 '07 #3
dmjpro
2,476 Top Contributor
I'm assigned to create a rectangle with inputs of height and width using the drawLine method and loops using asterisks(*).

I've done this without methods on a triangle, but I can't figure this one out.

Please help! thanks
Have a look at this code ...........

Expand|Select|Wrap|Line Numbers
  1. int length = 100, height = 200;
  2. for(int i=0;i<length;i++)
  3.  System.out.println("*");
  4. for(int i=1;i<height-1;i++){
  5.  System.out.println("*");
  6.  for(int j=1;j<length-1;j++)
  7.   System.out.println(" ");
  8.  System.out.println("*");
  9. }
  10. for(int i=0;i<length;i++)
  11.  System.out.println("*");
  12.  
Enjoy this code.
Good Luck !

Debasis Jana
Oct 5 '07 #4
JosAH
11,448 Recognized Expert MVP
Have a look at this code ...........

<snip>

Enjoy this code.
Good Luck !

Debasis Jana
Don't spoonfeed code.

kind regards,

Jos
Oct 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2202
by: Chris | last post by:
Hi, I found this code that can solve a problem I have. It sends print direct to printer. Imports System Imports System.Text Imports System.Runtime.InteropServices ...
9
1424
by: Claus Nietzsche | last post by:
hey people, i wrote this program, but i have troubles compiling it. my compiler keeps giving me error messages in this one line, and i cant figure out why. its in the line: void...
7
373
by: Katie | last post by:
my one base class is a linklist class.now i'd like to inherit it by another class.The problem is that when i use the derived class i can't access the base class's pointers.classic type mismatch.how...
0
1370
by: Trey | last post by:
I have a DataTable with a integer field called SortOrder. This table is loaded with and XML file. I have this table in a DataView and I set the RowFilter to filter some row, then I change the...
14
2705
by: Peter Mount | last post by:
Hello I'm having trouble with " scanf("%c", &answer);" on line 20 below. When I run the program in cygwin on Windows 98SE it skips that line completely and ends the program. Does scanf have...
4
2630
by: Colin McGuire | last post by:
Hi, this is a really simple question I have been banging my head on a brick wall over. The program below changes the background colour of a form depending on whether the cursor is inside a...
3
1521
by: Scott Gunn | last post by:
Hello all I'm trying to use the scrollwindowex api however I have the same problem as this guy had. There is an answer here in the reply. I just need some help converting it to VB.Net >Thanks...
1
3114
by: Unebrion | last post by:
Alright im working on a program that prints out user imput in a frame, along with a barcode.. it is like the front of an envelope. Here is the description for the program. This...
12
2983
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
1
5108
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.