Link to home
Start Free TrialLog in
Avatar of waltbaby315
waltbaby315

asked on

programing output average of each month

Im trying to print the average for each month, but so far I can only print January average. any suggestion?

class tempertures365  

{  

     public static void main(String args[])  

        {  

               int year[]=new int [365];  

               int i=0;  

               int monthSum=0;  

               int monthAverage=0;  

               int jan=0;  

               int feb=0;  

           System.out.println(" Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep Oct  Nov  Dec");  

                     

                   for (i=1;i<=31;i++)      

         {  

                 year[jan]=(int)Math.floor(25+Math.random()*(38-25+1));

         {

                   for (i=1;i<=31;i++)
          {
 
                 year[feb]=(int)Math.floor(26+Math.random()*(80-26+1));
                   
         System.out.println(" "+year[jan]);    

                 monthSum = monthSum + year[jan];  

         }  

                 monthAverage = (int) (monthSum / 31);  
         System.out.println("Avg for Jan. is "+monthAverage);
         System.out.println("Avg for Feb. is "+monthAverage);

         }  

  }


}
}
today.JPG
Avatar of for_yan
for_yan
Flag of United States of America image



 
Peerhaps you wanted something like below:

class tempertures365  

{  

     public static void main(String args[])  

        {  

               int year[]=new int [365];  

               int i=0;  

               int monthSum=0;  

               int monthAverage=0;  

               int jan=0;  

               int feb=0;  

           System.out.println(" Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep Oct  Nov  Dec");  

                             
   double tt = 0;
                   for (i=1;i<=31;i++)      


         {  

                 tt +=Math.floor(25+Math.random()*(38-25+1));

         }

        System.out.print("" + (int) (tt/31));
    tt = 0.0;
                  for (i=1;i<=28;i++)
          {
 
                 tt +=(int)Math.floor(26+Math.random()*(80-26+1));
                   
        // System.out.println(" "+year[jan]);    

           //      monthSum = monthSum + year[jan];  

         }  

      System.out.print("" + (int) (tt/28));
             //    monthAverage = (int) (monthSum / 31);  
        // System.out.println("Avg for Jan. is "+monthAverage);
        // System.out.println("Avg for Feb. is "+monthAverage);

    System.out.println("");
         }  

  }


}
}



 
Peerhaps you wanted something like below (correction):

class tempertures365  

{  

     public static void main(String args[])  

        {  

               int year[]=new int [365];  

               int i=0;  

               int monthSum=0;  

               int monthAverage=0;  

               int jan=0;  

               int feb=0;  

           System.out.println(" Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep Oct  Nov  Dec");  

                             
   double tt = 0;
                   for (i=1;i<=31;i++)      


         {  

                 tt +=Math.floor(25+Math.random()*(38-25+1));

         }

        System.out.print("" + (int) (tt/31));
    tt = 0.0;
                  for (i=1;i<=28;i++)
          {
 
                 tt +=Math.floor(26+Math.random()*(80-26+1));
                   
        // System.out.println(" "+year[jan]);    

           //      monthSum = monthSum + year[jan];  

         }  

      System.out.print("" + (int) (tt/28));
             //    monthAverage = (int) (monthSum / 31);  
        // System.out.println("Avg for Jan. is "+monthAverage);
        // System.out.println("Avg for Feb. is "+monthAverage);

    System.out.println("");
         }  

  }


}
}
Avatar of waltbaby315
waltbaby315

ASKER

No it still just prints out one month

it prints two moyths - there was no space between moths before


     int year[]=new int [365];

                int i=0;

                int monthSum=0;

                int monthAverage=0;

                int jan=0;

                int feb=0;

            System.out.println(" Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep Oct  Nov  Dec");


    double tt = 0;
                    for (i=1;i<=31;i++)


          {

                  tt +=Math.floor(25+Math.random()*(38-25+1));

          }

         System.out.print("" + (int) (tt/31) + "    ");
     tt = 0.0;
                   for (i=1;i<=28;i++)
           {

                  tt +=Math.floor(26+Math.random()*(80-26+1));

         // System.out.println(" "+year[jan]);

            //      monthSum = monthSum + year[jan];

          }

       System.out.print("" + (int) (tt/28)  + "      ");
              //    monthAverage = (int) (monthSum / 31);
         // System.out.println("Avg for Jan. is "+monthAverage);
         // System.out.println("Avg for Feb. is "+monthAverage);

     System.out.println("");
            

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial