63 213
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #6511 in Java | JSP | JSF for sya

Question #6511
prompts the user to enter 10 integers from 0 to 100. Keep these numbers in an array of integers named yourNumber[]. From this array, calculate and display the sum of all these 10 numbers. Next, identify and display the largest and the smallest number. Finally, provide the number of integers in this array which are odd numbers. Take note that all input from user will be handled by the input dialog method from JOptionPane class and all repetitive tasks must be executed using for or while loops.
Expert's answer
import javax.swing.JOptionPane;

public class Main {

private static
double yourNumber[]=new double[20];;
public static void main(String[] args)
{
String ans;
for(int i=0;i<10;i++){
ans =
JOptionPane.showInputDialog(null, "Enter element number "+ (i+1) + " from 0 to
100:");
yourNumber[i] = Double.parseDouble(ans);
}
String
answer="";
for(int
i=0;i<10;i++){
if(yourNumber[i]%2==1){
answer+=yourNumber[i]+"
";
}
}
JOptionPane.showMessageDialog(null, "Sum =
"+Sum(yourNumber)+"\n"+"Max = "+Max(yourNumber)+"\n"+"Min =
"+Min(yourNumber)+"\nOdd number is:
"+answer);
System.exit(0);
}
//Sum
private static double Sum(double
arayofNumber[]){
double sum=0;
for(int
i=0;i<10;i++){
sum+=arayofNumber[i];
}
return
sum;
}
//Function Min - smallest element in the array
public static
double Min(double arayofNumber[]){
double min=arayofNumber[0];
for(int
i=0;i<10;i++){
if(arayofNumber[i]<arayofNumber[0]){
min=arayofNumber[i];
}
}
return
min;
}
//Function Max - largest element in the array
public static
double Max(double arayofNumber[]){
double max=arayofNumber[0];
for(int
i=0;i<10;i++){
if(arayofNumber[i]>arayofNumber[0]){
max=arayofNumber[i];
}
}
return
max;
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions