خرید بک لینک

Vote count: 0

Take input from user in an array in form of numeric and show histogram Where i'm wrong The code is given in java the user can enter 5 input in number and histogram should show in any form with no constraints

    package p21;
    import java.util.Scaer;

    public class P21 {
    public static void main(String[] args) {
    {
    int count[]=new int[10];  // count array will keep elements of element
                              // in particular range;
     int elements[];       // for example   27 15 34 22 11 11 19
    {                                  // in above input there is count[0]=0;
     for(int i=0;i<elements.length;i++)   // count[1]=4 and count[2]=2 and count[3]=1;
    {
     if(elements[i]>=0 && elements[i]<50)
    {
      if(elements[i]<10)
     {
      count[0]++;
      }
      else if(elements[i]>=10 && elements[i]<20)
      {
       count[1]++;
      }
      else if(elements[i]>=20 && elements[i]<30)
      {
       count[2]++;
      }
      else if(elements[i]>=30 && elements[i]<40)
      {
       count[3]++;
    }
    else
    {
      count[4]++;
   }}
    else if(elements[i]>=50 &&elements[i]<=100)
   {
   if(elements[i]<60)
   {
      count[5]++;
   }
   else if(elements[i]>=60 && elements[i]<70)
    {
       count[6]++;
    }
   else if(elements[i]>=70 && elements[i]<80)
   {
       count[7]++;
   }
   else if(elements[i]>=80 && elements[i]<90)
   {
       count[8]++;
   }
   else
   {
       count[9]++;
   }}}}
   {
    System.out.println("Histogram of the elements:");
    for(int i=0;i<count.length;i++)     // this loop will print line
  {
   for(int j=0;j<count[i];j++)      // this will print elements element(*)
   {                                // at each line.
       System.out.print("* ");
   }
   if(count[i]!=0)                  // if line does'nt contain zero   
   System.out.println("");          // then if will change the row;
   }}}
   /*
   in above code if count[i]=zero means if there is elements
   element in particular range say [0-9] then it will
   elementst jump on next line;
   */
   {{
   Histogram hg=new Histogram();
   System.out.println("Enter the elements of Elements want in a  Histogram:");
 Scaer sc=new Scaer(System.in);

 int noOfElements=sc.nextInt();
 int histogramElements[]=new int[noOfElements];

 System.out.println("Enter the Elements for Histogram:");
  for(int i=0;i<noOfElements;i++)
   {
     histogramElements[i]=sc.nextInt();
    }

    hg.showHistogram(histogramElements);
    }

asked 50 secs ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 9 تير 1395 ساعت: 3:00

صفحه بندی