Advertisements
dear Sir/Mrs I'll be thankful for helping me on this .......
write a program that reads 10 numbers. find the largest number and count the occurrence of the largest number from a declared array. assume the assigned 4.6.3.2.5.6.6.1 and 6. the program will display the largest number os 6 and the count is 5.
note: 1-display the number in ascending order 2-display the number in descending order 3-display the total, average and the largest number
import java.util.*; class ArrayExample12{ public static void main(String[] args){ int sum=0,count=0; Scanner input=new Scanner(System.in); System.out.println("Enter Array Elements: "); int array[]=new int[10]; for(int i=0;i<array.length;i++){ int num=input.nextInt(); array[i]=num; } int maxValue = array[0]; for(int i=1;i < array.length;i++){ if(array[i] > maxValue){ maxValue = array[i]; } } for(int i=0;i<array.length;i++){ sum+=array[i]; if(array[i]==maxValue){ count++; } } System.out.println("Sum Of Numbers is: "+sum); System.out.println("Average of Numbers is: "+sum/array.length); System.out.println("Largest No: "+maxValue+" which occurs "+count+" times."); Arrays.sort(array); System.out.println("Numbers in increasing order: "); for(int i=0;i<array.length;i++){ System.out.println(array[i]); } System.out.println("Numbers in decreasing order: "); for(int i=array.length-1;i>=0;i--){ System.out.println(array[i]); } } }
Thank u very much ...... :)
could u put the "numbers in increasing order" and the "number in decreasing order" in one line ?? EX numbers in increasing order 1.2.3.4.5.6.7.8.9.10.