In: Computer Science
Input Format
A series of integers
Constraints
None
Output Format
The smallest number
Sample Input 0
1 10 6 4 -5 -4 0 .
Sample Output 0
Enter a series of integers, each on a different line. When done, enter a period. -5
Sample Input 1
100 12 89 66 .
Sample Output 1
Enter a series of integers, each on a different line. When done, enter a period. 12
import java.util.ArrayList;
import java.util.Scanner;
public class MinRec {
public static void main(String[] args) {
System.out.println("Enter a series of integers, each on a different line. When done, enter a period.");
Scanner sc = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<>();
while (sc.hasNextInt()) {
list.add(sc.nextInt());
}
int smallest = getSmallest(list);
System.out.println(smallest);
}
private static int getSmallest(ArrayList<Integer> list) {
return getMin(list, list.size());
}
private static int getMin(ArrayList<Integer> list, int n) {
if (n == 1)
return list.get(0);
return Math.min(list.get(n - 1), getMin(list, n - 1));
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME