java - Trying to add minimum and maximum outputs -
i have read few of suggested answers seem helpfuil complicated me confidently understand , add program.
can suggest ways output min , max 1st , 2nd years sales figures?
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"); } }
to maximum , minimum sales of arrays, can use java.util.arrays.sort
sort arrays , minimum sales first element of array , maximum sales last element of array.
example -
arrays.sort(sales); system.out.println("\nlowest sales year1 " + sales[0]); system.out.println("\nhighest sales year1 " + sales[sales.length-1]); arrays.sort(sales2); system.out.println("\nlowest sales year2 " + sales2[0]); system.out.println("\nhighest sales year2 " + sales2[sales2.length-1]);
Comments
Post a Comment