Hello,
I am trying to write a program that allows the user to enter a letter and using seven different methods to print out the letters.
This display should look like this
CCCCCCCCCC
CCCCCCCCCC
CCCCCCCCCC
CCC
CCC
CCC
CCCCCCCCCC
CCCCCCCCCC
CCCCCCCCCC
The method printBlock should accept a character and two integers.
For example , the call printBlock('*',5,3) would output
***
***
***
***
***
This is in java..can someone please help
Thanks,
jayjay

Two for-loops

commented: why make it harder if it indeed is this easy? +3

Two for-loops

I'm assuming you mean inside the method he has to create (just clearing it up because I was confused at first)

To jayjaysam0441:

I don't think you need seven methods; three calls on the same method, with different parameters should be fine.

public void printBlock(String character, int columns, int rows){
//for loops here

}


printBlock("C",3,10);
printBlock("C",3,3);
printBlock('"C",3,10);

I'm assuming you know how to receive user input but in case you don't. BufferedReader class

To recieve input from the command line I always use

//creates the object to read from the console
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

//takes whatever is typed in AKA the character you want printed 
//don't mind the try statement if you haven't been taught that yet

try{
String line = reader.readLine();
}catch(Exception e){}

You can probably get away with using one method, recursively until it resolves to an absolute base case.

I'm sure you can because I remember someone asking this same exact question, except they had to use recursion. They eventually found a solution.

Two for-loops

why try to figure out how to fly, if you can walk? just use two for loops as javaAddict suggested

why try to figure out how to fly, if you can walk? just use two for loops as javaAddict suggested

Because according to the OP, he was supposed to use a method called printBlock, and have a user supply the parameters. All you need inside the method are those two loops.

Because according to the OP, he was supposed to use a method called printBlock, and have a user supply the parameters. All you need inside the method are those two loops.

that was my point exactly :)

why try to figure out how to fly, if you can walk? just use two for loops as javaAddict suggested

Because some people receive inspiration to be a programmer by seeing all of the angles instead of just one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.