Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-27-2008, 05:34 AM
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
[SOLVED] Help Printign ASCII Pattern
Hi, I'm writing a simple program that will print the following two patterns:

Code:
######## ####### ###### ##### #### ### ## # ######## ####### ###### ##### #### ### ## #
However, I've written the method for the code called printPatterns. However, I'm not sure how to call the method within the main() in order to run the program. Here's the code thus far:

Code:
import Patterns.*; import java.io.*; import java.util.Scanner; import java.lang.String.*; public class Patterns { public void printPatterns() { int row=1, j=1; char OUTPUT='#'; System.out.println(); for (row = 1; row <= 8; row++) { for (j = 1; j <= row - 1; j++) { System.out.print(" "); } for (j = 1; j <= 9 - row; j++) { System.out.print(OUTPUT); } System.out.println(); } System.out.println(); for (row = 1; row <= 8; row++) { for (j = 1; j <= 9 - row; j++) { System.out.print(OUTPUT); } System.out.println(); } System.out.println(); } } public static void main (String[] args) { Patterns printPattern = new Patterns(); System.out.Patterns(); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-27-2008, 07:03 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public static void main (String[] args) { Patterns printPattern = new Patterns(); printPattern.printPatterns(); }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-27-2008, 07:08 AM
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
Haha, wow, I'm an idiot...sometimes the easiest answers evade me. Thanks.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-27-2008, 07:57 AM
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
Ok I've managed to get all that working but I was wondering if you could be of further help. I need to create several ASCII images, two of which I discussed above. One, however, is really bugging me. I can't seem to get the for loop statements to create it properly. the image appears basically like a 'Z'. Something like this:

Code:
######## # # # # # # ########
Thanks for any help!!
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 03-27-2008, 09:34 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,402
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Here it is in much simpler way.

Code:
int _row = 8; int _col = 8; for(int i = 0; i < _col;i++){ System.out.print("#"); if(i ==_row - 1){ for(int k = 2;k<_row;k++){ System.out.println(); for(int j = 0; j<_row -k;j++){ System.out.print(" "); } System.out.print("#"); } } } System.out.println(); for(int i = 0;i<_col;i++){ System.out.print("#"); }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 03-27-2008, 08:12 PM
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
Ok, thanks, I'll implement the simpler method. However, I'm still wondering if you could assist me with the loop for the 'Z' printout? Thanks.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 03-27-2008, 08:25 PM
Member
 
Join Date: Mar 2008
Posts: 14
wco5002 is on a distinguished road
Wow I'm sorry I didn't realize that's what that was for, thanks a lot.

Also, is there a way to simply manipulate that image to form another, perhaps something that looks like an hour glass like so:

Code:
# # # # # # # # # # # # # # # # # # # # # # # # # # # #
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 03-28-2008, 04:16 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,402
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I think you can try to do it quit similar way I have done to make 'z' shape. There I used a single space between two characters. Here in you shape there should be two spaces.

__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating ASCII character set JavaForums Java Blogs 2 09-15-2008 10:44 PM
How to obtain ASCII code of a character karma New To Java 4 07-20-2008 04:57 AM
Handling ASCII character set in Java (III) JavaForums Java Blogs 0 02-08-2008 11:31 AM
Getting ASCII codes of character gapper New To Java 1 02-02-2008 11:42 AM
Printing ASCII values of characters Java Tip Java Tips 0 01-21-2008 06:36 PM


All times are GMT +3. The time now is 02:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org