Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Nested Loops. Choose when to display character based on size of int.

$
0
0
I need to make half of a octagon, example below. I have the code written to read user input and check to make sure it meets all criteria. For this example below say that the user entered the Integer 4. The following needs to be printed:
    ####
   ######
  ########
 ##########



I'm pretty bad at loops and have tried drawing it out, but still stuck. Below is the code written and the output it prints:

int size = 4;
for(row = 0; row < size; row++) { 
		for(col = 0; col < size * 3; col++) {
			if(col < size) {
				System.out.print(".");
			}
			else{
			        System.out.print("#");
			}
		}
	System.out.println();
}


The output is:
....########
....########
....########
....########


Any help or guidance is most appreciated.

Thanks,

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>