aspose file tools*
The moose likes Java in General and the fly likes Java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java code" Watch "Java code" New topic
Author

Java code

Hasitha Nawanga
Greenhorn

Joined: Oct 26, 2012
Posts: 4
i wanna know what is the code of this output(using only one ("*")

*
**
***
****
*****
******

please help me...
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Welcome,

Now how do you think you would do that?

At least try something, and we'll be happy to help you through it.

WP
Hasitha Nawanga
Greenhorn

Joined: Oct 26, 2012
Posts: 4
class Hasi{
public static void main(String args[]){
System.out.println();
for(int x=0;x<1;x++)
System.out.print("*");
System.out.println();
for(int i=1;i<2;i++)
System.out.print("**");
System.out.println();
for(int x=0;x<1;x++)
System.out.print("***");
System.out.println();
for(int i=1;i<2;i++)
System.out.print("****");
}
}


this is my code.. but it has many *
Hasitha Nawanga
Greenhorn

Joined: Oct 26, 2012
Posts: 4
William P O'Sullivan

please help me man quickly....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39435
    
  28
Welcome to the Ranch

At least you didn’t use the magic word “urgent”. And please note: that link includes another link about subject lines.

You have some code which works, but as you have said yourself, there is repeated code. You have already worked out how to write one row of asterisks. Now all you have to do is work out how to print that row repeatedly.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Hasitha Nawanga wrote:
please help me man quickly....


Please EaseUp(←click). People here are volunteers and will answer in their own time. Asking people to hurry is considered rude, and will discourage them from helping you.
Hasitha Nawanga
Greenhorn

Joined: Oct 26, 2012
Posts: 4
Thank you.. and i'm very sorry..
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

A similar topic has already been discussed here.


The quieter you are, the more you are able to hear.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Hasitha,

some questions for you (since you said your answer is only to use one "*".. That's the clue).

How many rows are there?

How many stars in each row? (e.g: How many stars in row 3?)

What is the simplest form of a Java loop?

How do you append Strings?

Once you start thinking about the tools and data at your disposal, the answer should come quickly.

WP
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java code