943,926 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 607
  • Java RSS
Aug 23rd, 2009
0

Hurry help me

Expand Post »
how can i print a triangle in java.Its shape is like this
A
B C
D E F
G H I J
K L M N O
i have to use ascii code for printing alphabets.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Master Piece is offline Offline
5 posts
since Aug 2009
Aug 23rd, 2009
-3

Re: Hurry help me

Try this, it should work:
java Syntax (Toggle Plain Text)
  1. class print_ascii
  2. {
  3. static void ascii()
  4. {
  5. for(int j=1;j<=26;j++)
  6. {
  7. int n=65;
  8. for(int i=1;i<=j;i++)
  9. {
  10. char a=(char)n;
  11. System.out.print(a+" ");
  12. n++;
  13. }
  14. System.out.println();
  15. }
  16. }
  17. }
Reputation Points: 2
Solved Threads: 30
Posting Whiz in Training
sravan953 is offline Offline
242 posts
since May 2009
Aug 23rd, 2009
0

Re: Hurry help me

i am new in programming plz tell me,will i have to give a value on runtime??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Master Piece is offline Offline
5 posts
since Aug 2009
Aug 23rd, 2009
0

Re: Hurry help me

C:\jdk1.3\bin>javac print.java

C:\jdk1.3\bin>java print
Exception in thread "main" java.lang.NoSuchMethodError: main
.This was given by the program
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Master Piece is offline Offline
5 posts
since Aug 2009
Aug 23rd, 2009
0

Re: Hurry help me

thanks i solved this problem.But i have to print till "J" only what should i do.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Master Piece is offline Offline
5 posts
since Aug 2009
Aug 23rd, 2009
0

Re: Hurry help me

what should i do i have to print till "J" only
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Master Piece is offline Offline
5 posts
since Aug 2009
Aug 23rd, 2009
0

Re: Hurry help me

Just before you print each letter, check to see if its greater than 'J', if it is, you can exit your program immediately (exit is a method in the System class)
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008
Aug 24th, 2009
0

Re: Hurry help me

Java Syntax (Toggle Plain Text)
  1. class print_ascii
  2. {
  3. static void ascii()
  4. {
  5. for(int j=1;j<=26;j++)
  6. {
  7. int n=65;
  8. for(int i=1;i<=j;i++)
  9. {
  10. char a=(char)n;
  11. System.out.print(a+" ");
  12. n++;
  13. }
  14. System.out.println();
  15. }
  16. }
  17. }
Last edited by John A; Aug 26th, 2009 at 12:08 am. Reason: added code tags
Reputation Points: -1
Solved Threads: 0
Junior Poster in Training
coud_ren_26 is offline Offline
67 posts
since Aug 2009
Aug 24th, 2009
0

Re: Hurry help me

Yes, and... ?
Featured Poster
Reputation Points: 1924
Solved Threads: 952
Posting Expert
JamesCherrill is offline Offline
5,788 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Re: FileReader
Next Thread in Java Forum Timeline: Using Prepared Statements in JAVA





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC