Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class BiggerThanFirstAndLastAverage {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- int A[]; // Needs to be initialized with sorted values
- System.out.printf("What size is your array? ");
- A = new int[in.nextInt()];
- int smallerThanAverage = smallerThanKey(A, ((A[0] + A[A.length - 1]) / 2));
- System.out.printf("%s", smallerThanAverage >= A.length ? "Most values are less than first and last average" : "Most values are more than first and last average");
- in.close();
- }
- private static int smallerThanKey(int[] array, int key)
- {
- int result = 0;
- for(int i = 0; i < array.length; i++)
- {
- if(array[i] > key)
- break;
- else
- result++;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement