Access over 20 million homework & study documents

Create an application containing an array that stores 10 integers Th

Content type
User Generated
Rating
Showing Page:
1/5
Create an application containing an array that stores 10
integers. The application should call five methods that in
turn (1) display all the integers, (2) display all the integers
in reverse order, (3) display the sum of the integers, (4)
display all values less than a limiting argument, and (5)
display all values that are higher than the calculated
average value. Save the file as ArrayMethodDemo.java.
Solution
ArrayMethodDemo.java
import java.util.Scanner;
public class ArrayMethodDemo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a[] = new int[10];
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter 10 integer values :\");
for(int i=0; i<10; i++){
a[i] = scan.nextInt();

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/5
}
displayArray(a);
displayArrayReverse(a);
sumArray(a);
System.out.println(\"Enter Limit value:\");
int limit = scan.nextInt();
arrayElementsLessThanLimit(a, limit);
arrayElementsHigherThanAvg(a);
}
public static void displayArray(int a[]){
System.out.println(\"Array Elements: \");
for (int i = 0; i < a.length; i++)
System.out.print(a[i]+\" \");
System.out.println();
}
public static void displayArrayReverse(int a[]){
System.out.println(\"Array Elements in reverse order :
\");
for (int i = a.length-1; i >0 ; i--)
System.out.print(a[i]+\" \");
System.out.println();
}
public static int sumArray(int a[]){
int sum = 0;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/5

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 5 pages?
Access Now
Unformatted Attachment Preview
Create an application containing an array that stores 10 integers. The application should call five methods that in turn (1) display all the integers, (2) display all the integers in reverse order, (3) display the sum of the integers, (4) display all values less than a limiting argument, and (5) display all values that are higher than the calculated average value. Save the file as ArrayMethodDemo.java. Solution ArrayMethodDemo.java import java.util.Scanner; public class ArrayMethodDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int a[] = new int[10]; Scanner scan = new Scanner(System.in); System.out.println(\"Enter 10 integer values :\"); for(int i=0; i0 ; i--) System.out.print(a[i]+\" \"); System.out.println(); } public static int sumArray(int a[]){ int sum = 0; for(int i=0; i ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Great! Studypool always delivers quality work.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4