# Thread: Getting rid of astericks

1. Member Join Date
Mar 2014
Posts
16
Rep Power
0

## Getting rid of astericks

This is my code so far which is correct my only problem is that I have to make it so there doesn't become more than 50 astericks on a line and I don't know how to do that I know the code is something divided by 50 but I dont understand where I would put it.
************************************************** ******************(pretend it was 100 astericks)
it would be
****************************************(x<50 astericks or 42)
import java.util.*;
public class Graph {
private int [] counter;

public Graph(int x)
{
counter=new int;
}
public void countIt(int x)
{
counter[x]++;
}

public void GraphIt()
{
for(int i =0; i<=1000000; i++)
{

for(int j=0; j<counter[i]-1;j++)
{
System.out.print("*");
}

System.out.println("");

}
}
}
class TestMyGraph
{
public static void main(String[] args)
{
Graph g= new Graph(5);
Random r=new Random();
g.countIt(r.nextInt(5));
for(int k=0; k<=1000;k++)
{
g.countIt(r.nextInt(5));

}
g.GraphIt();
}
}  Reply With Quote

2. ## Re: Getting rid of astericks

[code]
[/code]
to get highlighting and preserve formatting.

there doesn't become more than 50 astericks on a line
Count the asterisks as they are printed on a line and stop printing them when the count gets to 50.  Reply With Quote

3. Member Join Date
Mar 2014
Posts
16
Rep Power
0

## Re: Getting rid of astericks

Java Code:
```import java.util.*;
public class Graph {
private int [] counter;

public Graph(int x)
{
counter=new int;
}
public void countIt(int x)
{
counter[x]++;
}

public void GraphIt()
{
for(int i =0; i<=1000000; i++)
{

for(int j=0; j<counter[i]-1;j++)
{
System.out.print("*");
}

System.out.println("");

}
}
}
class TestMyGraph
{
public static void main(String[] args)
{
Graph g= new Graph(5);
Random r=new Random();
g.countIt(r.nextInt(5));
for(int k=0; k<=1000;k++)
{
g.countIt(r.nextInt(5));

}
g.GraphIt();
}
}```
would I use an if statement in order to do that  Reply With Quote

4. Member Join Date
Mar 2014
Posts
16
Rep Power
0

## Re: Getting rid of astericks

It needs to still be in this format I just need it to divide at 50 each time it goes over 50  Reply With Quote

5. ## Re: Getting rid of astericks

Yes, an if statement could be used to detect a value of the counter.  Reply With Quote

6. Member Join Date
Mar 2014
Posts
16
Rep Power
0

## Re: Getting rid of astericks

okay so:

if(counter[i]>50)
counter[i]/50;
? would it be like that and where would I put it inbtween the nested for loop  Reply With Quote

7. ## Re: Getting rid of astericks

Try one then the other to see what they do.

What is the code supposed to do when 50 is reached? What code should be inside of the if?  Reply With Quote

8. Member Join Date
Mar 2014
Posts
16
Rep Power
0

## Re: Getting rid of astericks

public void GraphIt()
{
for(int i =0; i<=1000000; i++)
{

for(int j=0; j<counter[i]-1;j++)
{
System.out.print("*");

if(counter[j]>50)
{
counter[i]=counter[j]/50;
}
}
System.out.println("");

}
}
}
THis is it I believe  Reply With Quote

9. ## Re: Getting rid of astericks

THis is it I believe
Have you solved your problem now?

[code]
[/code]
to get highlighting and preserve formatting.  Reply With Quote

10. Member Join Date
Mar 2014
Posts
16
Rep Power
0

## Re: Getting rid of astericks

Java Code:
```public void GraphIt()
{
for(int i =0; i<=1000000; i++)
{

for(int j=0; j<counter[i]-1;j++)
{
System.out.print("*");

if(counter[j]>50)
{
counter[i]=counter[j]/50;
}
}
System.out.println("");

}
}
}```
Now what the if statement is going to do is the print statement every time it goes over 50 astericks based off of the random number then it will divide by 50 and start over again and repeat the process so it keeps track the array from 0-4 then will divide by 50 every time it becomes more than 50  Reply With Quote

11. ## Re: Getting rid of astericks

Does that code do what you want?

The formatting is messed up in the last post. All the indentations have been lost.

Hint for testing: Don't use such large numbers. Use a number that is easily verified by looking at the printout. Say 5 vs 50 and 100 vs 1000
Last edited by Norm; 03-19-2014 at 09:22 PM.  Reply With Quote

12. Member Join Date
Mar 2014
Posts
16
Rep Power
0

## Re: Getting rid of astericks

Yes it does percisley what I want I understand its messed up because of how I copied it in it is nicely formatted in my IDE thank you for your help  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•