Results 1 to 2 of 2
  1. #1
    swilliams236 is offline Member
    Join Date
    Nov 2011
    Posts
    13
    Rep Power
    0

    Default Help getting Histogram chart example working

    I have a histogram chart that I was given as an example. As I understand it, it is supposed to be working code, however, I can't get it to successfully compile.

    I keep getting an error "operator <= cannot be applied to int,int[]"

    Can someone help me see what I am missing? Am I supposed to be passing data to it from a section of my code? I'm having an incredibly hard time with graphing even after reading the tutorials. I can draw pre-defined shapes such as lines, rectangles, etc. but I am struggling with this one.

    Your help is greatly appreciated.

    Java Code:
    import javax.swing.*;
    
    public class Histogram
    {
     public static void main(String args[])
     {
      int n[] = {19, 3, 20, 7, 13, 19, 3, 19,1};
      String output = "";
    
      output += "Element \tValue\tHistogram";
    
      for (int i = 0; i < n.length; i++)
      {
       output += "\n" + i + "\t" + n + "\t";
    
       //prints the bar
       for (int j = 1; j <= n; j++)
        output += '*';
      }
    
      JTextArea outputArea = new JTextArea(11, 30);
      outputArea.setText(output);
    
      JOptionPane.showMessageDialog(null , outputArea,
      "Histogram Class",
      JOptionPane.INFORMATION_MESSAGE);
    
      System.exit(0);
    
    
     }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Help getting Histogram chart example working

    j <= n

    j is an int and n is an array. Can you explain to me how an int can be greater or less than an array?
    Last edited by Junky; 11-21-2011 at 05:24 AM.

Similar Threads

  1. Help with histogram
    By Conan in forum New To Java
    Replies: 5
    Last Post: 11-02-2011, 03:51 AM
  2. need help with name histogram
    By cachico12 in forum New To Java
    Replies: 1
    Last Post: 05-09-2011, 08:27 AM
  3. Replies: 0
    Last Post: 02-08-2011, 08:51 AM
  4. histogram
    By little_man in forum New To Java
    Replies: 4
    Last Post: 11-13-2010, 01:38 AM
  5. Demo bar chart and pie chart
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 11:22 PM

Posting Permissions

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