java - I cannot replace the counter 0-11 with months of the year -


i want output show months , sales figures don't know replace what.

i have tried adding code make months appear , numbers right i'm having no luck.

import java.util.scanner;     public class assignment2     {      public static void main(string[] args)         {         scanner keyboard = new scanner(system.in);          system.out.println("welcome!\n");         system.out.println("month 0 - january");         system.out.println("month 11 - december\n");         system.out.println("monthno(year1)\tsales made\n");          double sales[] = { 60, 54, 62, 67, 54, 67, 51, 50, 62, 55, 49, 70 };         int sum = 0;         int average12 = 0;          (int counter = 0; counter < sales.length; counter++)             {             sum += sales[counter];             system.out.println(counter + "\t\t\t\t\t\t" + sales[counter]);              }          system.out.println("\ntotal year 1 sales " + sum + "\n");      ///////////////////////////////////////////////////////////////////////////          system.out.println("monthno(year2)\tsales made\n");          double sales2[] = { 59, 43, 48, 51, 49, 57, 39, 42, 54, 51, 60, 62 };         int sum2 = 0;          (int counter = 0; counter < sales2.length; counter++)             {             sum2 += sales2[counter];             system.out.println(counter + "\t\t\t\t\t\t" + sales2[counter]);             }          system.out.println("\ntotal year 2 sales " + sum2 + "\n");      }   } 

the output -

welcome!  month 0 - january month 11 - december  monthno(year1)  sales made  0                       60.0 1                       54.0 2                       62.0 3                       67.0 4                       54.0 5                       67.0 6                       51.0 7                       50.0 8                       62.0 9                       55.0 10                      49.0 11                      70.0  total year 1 sales 701  monthno(year2)  sales made  0                       59.0 1                       43.0 2                       48.0 3                       51.0 4                       49.0 5                       57.0 6                       39.0 7                       42.0 8                       54.0 9                       51.0 10                      60.0 11                      62.0  total year 2 sales 615 

you declare string array months , store names of months in below:

string[] months = {"january", "february", .......}; 

now in places used counter in system.out.println use months[counter].

this hope solve problem.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -