Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java code

 
Hasitha Nawanga
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wanna know what is the code of this output(using only one ("*")

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

please help me...
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan

please help me man quickly....
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.. and i'm very sorry..
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A similar topic has already been discussed here.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic