Instantly share code, notes, and snippets.

Embed
What would you like to do?
CSC-111 Array In class Challenge
/*
* Name:
* Date:
* Course Number:
* Course Name:
* Problem Number:
* Email:
* Short Description of the Problem
*/
import java.util.Scanner;
public class FindMinApp {
private static int[] readIntegers(Scanner input, int count) {
int[] array = new int[count];
for (int i = 0; i < array.length; i++) {
System.out.println("Enter a number:");
int number = input.nextInt();
array[i] = number;
}
return array;
}
private static int findMin(int[] array) {
return -99999;
}
//**********************************************
private static void process(Scanner sc, String args[]) {
System.out.println("Enter count:");
int count = sc.nextInt();
int[] returnedArray = readIntegers(sc, count);
sc.nextLine(); // Clears Keyboard
int returnedMin = findMin(returnedArray);
System.out.println("min = " + returnedMin);
}
//**********************************************
private static boolean doThisAgain(Scanner sc, String prompt) {
System.out.print(prompt);
String doOver = sc.nextLine();
return doOver.equalsIgnoreCase("Y");
}
//**********************************************
public static void main(String args[]) {
final String TITLE = "CSC111 Project Template";
final String CONTINUE_PROMPT = "Do this again? [y/N] ";
System.out.println("Welcome to " + TITLE);
Scanner sc = new Scanner(System.in);
do {
process(sc, args);
} while (doThisAgain(sc, CONTINUE_PROMPT));
sc.close();
System.out.println("Thank you for using " + TITLE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment