Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


luther wardle
luther wardle
Full Stack JavaScript Techdegree Student 18,029 Points

making a histogram in java

Hello All, I'm trying to make a histogram (intake int values from a sheet then separate them into their numbered sets 1-10, 11-20, etc all the way to 100)

I was hoping someone could tell me what i'm doing wrong in terms of being able to store values in arrays and print out "*" to represent 1 datapoint in that array

ultimately the program should look like this:

each line is the quantity of numbers stored in each consequitive array. can anyone give me any pointers?

luther wardle
luther wardle
Full Stack JavaScript Techdegree Student 18,029 Points

MY APOLOGIES! here is my code

import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner;

public class Histogram {

public static void main(String[] args) throws FileNotFoundException {
    Scanner fileScan=new Scanner(new FileReader("histogram3.txt"));
    File f = new File("histogram3.txt");
    int input=fileScan.nextInt();   
    int tencount = 0;
    int twencount = 0;
    //int thircount = 0;
    //int fortcount = 0;
    //int fiftcount = 0;
    //int sixtcount = 0;
    //int sevecount = 0;
    //int eighcount = 0;
    //int ninecount = 0;
    //int huncount = 0;

    int ten[]=new int[1000];
    int twen[] = new int[1000];
    //int thir[]=new int[1000];
    //int fort[] = new int[1000];
    //int fivt[]=new int[1000];
    //int sixt[] = new int[1000];
    //int seve[]=new int[1000];
    //int eigh[] = new int[1000];
    //int nine[]=new int[1000];
    //int hund[] = new int[1000];

    while(fileScan.hasNextLine()) {
        if(input<=10) {
        if(input<=20) {


    //print stars based on length of array
    for(int star=0; star<tencount;star++) {



1 Answer

Were you able to figure it out?