Last active
December 10, 2019 22:08
-
-
Save lbattaglioli2000/a7c21cba1a26b6ff9cd762f6864f45eb to your computer and use it in GitHub Desktop.
CISS110 Fmax Array Assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Fmax { | |
public static void main(String[] args) | |
{ | |
int[] fmax = fillFmax(new int[13]); | |
// int[] testingFmaxArray = {85, 78, 97, 88, 77, 62, 101, 98, 89, 105, 87, 74, 67}; | |
int max = maxFmax(fmax); | |
int min = minFmax(fmax); | |
printFmax(fmax); | |
System.out.printf("\nThe maximum value is: %d\n", fmax[max]); | |
System.out.printf("This is index number %d in the list of numbers.\n", max); | |
System.out.printf("The minimum value is: %d\n", fmax[min]); | |
System.out.printf("This is index number %d in the list of numbers.\n\n", min); | |
} | |
/** | |
* fillFmax | |
* | |
* Fills the inputted int[] array with the number | |
* that the user provided. | |
* | |
* @param fmax | |
* @return int[] fmax | |
*/ | |
public static int[] fillFmax(int[] fmax) | |
{ | |
Scanner s = new Scanner(System.in); | |
for(int i = 0; i < fmax.length; i++){ | |
System.out.printf("Enter number %d: ", i + 1); | |
fmax[i] = s.nextInt(); | |
System.out.println(); | |
} | |
s.close(); | |
return fmax; | |
} | |
/** | |
* maxFmax | |
* | |
* Finds the maximum number within the inputted | |
* fmax int[] array. | |
* | |
* @param fmax | |
* @return int maximumIndex | |
*/ | |
public static int maxFmax(int[] fmax) | |
{ | |
int max = fmax[0]; | |
int index = 0; | |
for(int i = 0; i < fmax.length; i++){ | |
if(fmax[i] > max){ | |
max = fmax[i]; | |
index = i; | |
} | |
} | |
return index; | |
} | |
/** | |
* minFmax | |
* | |
* Finds the minimum number within the inputted | |
* fmax int[] array. | |
* | |
* @param fmax | |
* @return int minimumIndex | |
*/ | |
public static int minFmax(int[] fmax) | |
{ | |
int min = fmax[0]; | |
int index = 0; | |
for(int i = 0; i < fmax.length; i++){ | |
if(fmax[i] < min){ | |
min = fmax[i]; | |
index = i; | |
} | |
} | |
return index; | |
} | |
/** | |
* printFmax | |
* | |
* Prints out the inputted int[] array. | |
* | |
* @param fmax | |
*/ | |
public static void printFmax(int[] fmax) | |
{ | |
// Given: {85, 78, 97, 88, 77, 62, 101, 98, 89, 105, 87, 74, 67} | |
System.out.printf("\n%-15s %-15s\n", "Index Number", "Array Value"); | |
System.out.println("---------------------------"); | |
for(int i = 0; i < fmax.length; i++){ | |
System.out.printf("%-15d %-15d\n", i, fmax[i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 39,
s.close();
, there's no need to add. That's just me flexing my massive wiener on Whollober.