Write a java program that will do sum of numbers, find average, find any given number and sort all numbers


 Sum of numbers, find average, find any given number, sort all numbers


Write a java program that will do sum of numbers, find average, find any given number and sort all numbers,Sum of numbers, find average, find any given number and sort all numbers in java

import java.util.Scanner;

class Question_21{

public int a[]=new int[20];

public Question_21(){

Scanner scan=new Scanner(System.in);

System.out.println("Enter values :"); // 3,2,1,7,6,4,8,5,10,9

for(int i=0;i<10;i++)

a[i]=scan.nextInt();

}

public void display(){

System.out.println("\n\nArray .....");

for(int i=0;i<10;i++)

System.out.println(a[i]+" , ");

}

public void sum(){

int tot=0;

for(int i=0;i<10;i++) //i=0;0<10(True) //i=1;1<10(True)

tot+=a[i]; //total=0+3=3 //total=3+2=5 and so on

System.out.println("Sum of 10 no is : "+tot); //tot

}

public void avg(){

int tot=0,i;

for (i=0;i<10;i++)

tot+=a[i];

System.out.println("Average of 10 no is : "+(tot/(double)i));

}

public void find(){

Scanner scan=new Scanner(System.in);

System.out.println("\n\nEnter finding value :");

int b=scan.nextInt();

for (int i=0;i<10;i++)

if(a[i]==b){

System.out.println("\n\nValue found at "+(i+1)+" Place...");

return;

}

System.out.println("\n\nValue not found.....");

}

public void sort(){

int b[]=new int[10];

for (int i=0;i<10;i++)

b[i]=a[i];

for (int i=0;i<10;i++)

for (int j=i+1;j<10;j++)

if(b[i]>b[j]){

int temp=b[j];

b[j]=b[i];

b[i]=temp;

}

System.out.println("\n\nSorted Array .....");

for (int i=0;i<10;i++)

System.out.print(b[i]+" , ");

}

public static void main(String args[]){

a21 arr=new a21();

Scanner scan=new Scanner(System.in);

int c=0;

while(c!=6){

System.out.println("\n\nSelection Opertion  :\n 1.Display  2.Sum  3.Average  4.Finding  5.Sort  6.Quit\n Enter Selection :");

c=scan.nextInt();

switch(c){

case 1 : arr.display(); break;

case 2 : arr.sum(); break;

case 3 : arr.avg(); break;

case 4 : arr.find(); break;

case 5 : arr.sort(); break;

case 6 : System.out.println("Quit....."); break;

default : System.out.println("Invaild....");

}

}

}

}

Array operations in java

Know more about Samsung Galaxy F41

Comment your views on this Article :)


Thank you for visiting my blog :)


No comments

Comment your views on this article

Powered by Blogger.