Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. Scanner input = new Scanner(System.in);
  2.  
  3. int array[] = new int[10];
  4.  
  5. System.out.println("Enter the numbers now.");
  6.  
  7. for (int i = 0; i < array.length; i++) {
  8. int next = input.nextInt();
  9. // sentineil that will stop loop when 999 is entered
  10. if (next == 999) {
  11. break;
  12. }
  13. array[i] = next;
  14. // get biggest number
  15. getMaxValue(array);
  16. // get smallest number
  17. getMinValue(array);
  18. }
  19.  
  20. System.out.println("These are the numbers you have entered.");
  21. printArray(array);
  22.  
  23.  
  24. // getting the maximum value
  25. public static int getMaxValue(int[] array) {
  26. int maxValue = array[0];
  27. for (int i = 1; i < array.length; i++) {
  28. if (array[i] > maxValue) {
  29. maxValue = array[i];
  30. }
  31. }
  32. return maxValue;
  33. }
  34.  
  35. // getting the miniumum value
  36. public static int getMinValue(int[] array) {
  37. int minValue = array[0];
  38. for (int i = 1; i < array.length; i++) {
  39. if (array[i] < minValue) {
  40. minValue = array[i];
  41. }
  42. }
  43. return minValue;
  44. }
  45.  
  46. //this method prints the elements in an array......
  47. //if this case is true, then that's enough to prove to you that the user input has //been stored in an array!!!!!!!
  48. public static void printArray(int arr[]) {
  49. int n = arr.length;
  50.  
  51. for (int i = 0; i < n; i++) {
  52. System.out.print(arr[i] + " ");
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement