The Artima Developer Community
Sponsored Link

Java Answers Forum
Simple method - requires urgent help!

2 replies on 1 page. Most recent reply: Jul 7, 2003 2:59 PM by Sharon

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Sharon

Posts: 4
Nickname: jbeginner
Registered: Jul, 2003

Simple method - requires urgent help! Posted: Jul 6, 2003 4:09 AM
Reply to this message Reply
Advertisement
If you could help me with this method I would be very grateful!

Write a method that takes an integer argument w and returns without printing anything if w is less than 1 but otherwise prints out a triangle of asterisk sysmbols satisfying the following conditions:
- Every line contains only space (' ') and asterisk ('*') symbols
- Every line contains exactly w characters
- There are w lines of output
- The first line contains 1 asterisk, and, in general, the nth line contains n asterisks.
- On every line all the asterisks appear at the end of the line.
The only print methods you may use are System.out.print(char ch), which outputs a single character ch, and System.out.println() which terminates the current line (ie you may only output one character at a time and not whole strings of characters).
Eg when called with the argument 4, the method will print out the four lines:
*
**
***
****


Alien

Posts: 1
Nickname: alien
Registered: Jul, 2003

Re: Simple method - requires urgent help! Posted: Jul 6, 2003 5:10 AM
Reply to this message Reply
Hi,

class Asterisk
{
public static void main(String[] args)
{
Asterisk a = new Asterisk();
a.print(3);
}
private void print(int w)
{
int i=0;
do {
++i;
for(int j=0;j<i;j++)
System.out.print('*');
System.out.println(' ');
}while (i<w);
}
}
Cheerz.

Sharon

Posts: 4
Nickname: jbeginner
Registered: Jul, 2003

Re: Simple method - requires urgent help! Posted: Jul 7, 2003 2:59 PM
Reply to this message Reply
Thank you so much for help and quick response! I am taking a Java exam at the end of August and I need all the help I can get - my university career depends on it - so cheers again!

Flat View: This topic has 2 replies on 1 page
Topic: Trying to get rating applet to work Previous Topic   Next Topic Topic: How can I allow a user (client) to choose a local image file (on his hard d

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use