Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java Help - update

  Asked By: Daryl    Date: Dec 14    Category: Java    Views: 881
  

import java.io.*;
import javagently.*;

class Rectangle {
int width;
int height;
/** Creates new Rectangle */
Rectangle(int argWidth, int argTall) {
width = argWidth;
height = argTall;
}
/** Display's a rectangle */

void show () {






// This is a for-loop.
// This is supposed to create a 4X4 hollow square
//ASterisks. FROM THE VOID SHOW () {.....
// TO............................ ...}
//.......................PUBLIC STATIC VOID
//ALL THE BRACKETS ARE REQUIRED. IT IS THE INNER ARGUMENT
// THAT I CANNOT FIXED---->The brackets are all paired
// And are even in number...THANKS!


for(int i = 0; i < argWide; i++) {
System.out.print("*");
{
System.out.print("\n");
for(int i = 0; i < (argTall - 2); i++) {
System.out.print("*")
for(int j = 0; j < (argWide - 2); j++) {
System.out.print(" ");
}
System.out.println("*");







}
public static void main(String [] args) {
Rectangle aRect = new Rectangle(4,4);
aRect.show();
}
}

//How do I modify this if i also want a 9X7 rectangle?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Frederick Greene     Answered On: Dec 14

May be u can try out this program

import java.io.*;


class Rectangle {
int width;
int height;
/** Creates new Rectangle */
Rectangle(int argWidth, int  argTall) {
width = argWidth;
height = argTall;
}
/** Display's a rectangle */

void show()
{
Length(width);
System.out.println("");
Breadth(height,width);
Length(width);
}

void Length(int l)
{
for(int i=0;i<l;i++)
{
System.out.print("*");
}
}
void Breadth(int b,int l)
{
for(int j =0;j<b;j++)
{
for(int i=0;i<l;i++)
{
if(i==0 || i==l-1)
System.out.print("*");
else
System.out.print(" ");
if(i==l-1)
System.out.print("\n");
}
}
}



public static void  main(String [] args) {
Rectangle aRect = new Rectangle(90,17);
aRect.show();
}
}

 
Didn't find what you were looking for? Find more on Java Help - update Or get search suggestion and latest updates.




Tagged: