Write a program which reads 10 decimal numbers in an array a

Write a program which reads 10 decimal numbers in an array and sums all array elements and displays total on screen Create an array of type double with 10 elements Using for loop sum all elements of array and use first element for result storage Display results (sum of all elements) Write a program which perform following tasks a) Read 5 student names in a two dimensional character array b) Sort student names in ascending order c) Display sorted array

Solution

1)

import java.util.Scanner; class Sum
{
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
Double[] array = new double[10];
Double sum = 0.0; System.out.println(\"Enter the elements:\");
for (int i=0; i<10; i++)
{   
array[i] = scanner.nextInt();
} for( int num : array)
{
sum = sum+num;
} System.out.println(\"Sum of array elements is:\"+sum);
}
}


2)

class sorting
{   
public static void main(String[] input)
    {   
   int k=input.length;       
String temp=new String();
   String names[]=new String[k+1];       
for(int i=0;i<k;i++)   
   {       
   names[i]=input[i];       
}   
   for(int i=0;i<k;i++)            for(int j=i+1;j<k;j++)   
       {                if(names[i].compareTo(names[j])<0)           
   {                    temp=names[i];                    names[i]=names[j];                    names[j]=temp;           
   }
           } System.out.println(“Sorted order is”);
for(int i=0;i<k;i++)
{       
   System.out.println(names[i]);
}
}
}

 Write a program which reads 10 decimal numbers in an array and sums all array elements and displays total on screen Create an array of type double with 10 elem

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site