import java.util.Scanner;
class Numeral
{
Scanner s= new Scanner(System.in);
int arr[] =new int[10];
{
System.out.println("enter the ten number of array");
for(int i=0;i<10;i++) {
arr[i]=s.nextInt();
}
}
}
class Numplay extends Numeral{
double sum=0;
double avg;
int temp=0;
void display() {
System.out.println("you entered elements is:");
for(int i=0;i<10;i++) {
System.out.print(" "+arr[i]);
}
}
void getsum() {
for(int i=0;i<10;i++) {
sum=(sum+arr[i]);
}
System.out.println("Ans-2)the sum is :"+sum);
}
void getaverage() {
for(int i=0;i<10;i++) {
sum=(sum+arr[i]);
}
double avr = sum/10;
System.out.println("ans-3)the average is :"+avr);
}
void findMaximum() {
int max=arr[0];
for(int i=0;i<10;i++) {
if(max<arr[i]) {
max=arr[i];
}
}
System.out.println("the max num is :"+max);
}
void findminimum() {
int x=arr[0];
for(int i=1;i<9;i++) {
if(x>arr[i]) {
x=arr[i];
}
}
System.out.println("the minimum num is :"+x);
}
void app() {
System.out.println("enter method choice:"+'\n'+"display: enter num"+'\n'+"'sum: enter 2"+'\n'+"average:enter 3"+'\n'+"max:enter 4"+'\n'+"min:enter 5");
int choice =s.nextInt();
switch(choice) {
case 1:
display();
break;
case 2:
getsum();
break;
case 3:
getaverage();
break;
case 4:
findMaximum();
break;
default:
System.out.println("invalid choice");
}
}
}
public class ankush{
public static void main(String[] args) {
Numplay num=new Numplay();
num.app();
}
}
No comments:
Post a Comment