Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Need help creating an empty square

nested loop

  • Please log in to reply
1 reply to this topic

#1 jsnjt03


    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 21 September 2011 - 06:31 AM

I need help creating a square that is empty. The square would have the same number of asterisks on each side. The size is decided on user input. I just have an issue on understanding nested loops please help.
* *
* *

public class square
	public static void main(String[] args)
		//declare keyboard as scanner type
		Scanner keyboard = new Scanner(System.in);
		//get input from the user
		System.out.print("Please enter a value of height (1-20): ");
		//declare height as int
		int height = keyboard.nextInt();
		//Run a group of nested for loops to make a square
			for(int i = 0; i < height; i++)
				for(int j = 0; j <= height; j++);

Edited by Roger, 21 September 2011 - 11:47 AM.
moved + added code tags.

  • 0

#2 Vaielab


    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts
  • Location:Quebec City
  • Programming Language:Java, C++, C#, PHP, JavaScript, Visual Basic .NET, Transact-SQL, ActionScript

Posted 21 September 2011 - 08:03 AM

This look like java... this is the javascript section, you should try posting it in the right section you will have more chance of getting help
Plus it seem that you miss the end of your code

This really look like a school homework, so we can't give you the answer, but look at the line System.out.print('*'); if you want en empty square, you should think of putting a condition near it
if it is not the first or last row and if it is not the first or last columns
  • 0

Also tagged with one or more of these keywords: nested loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download