I need help to calculate the two smallest numbers in java? ... plzz help .. Use for arraylist and arrays is not allowed. First, the user will be asked to get the final value and will continue to provide input data and once the user enters the same final value, the program should output the two smallest numbers from the inputs, excluding the final value.
Additional information Could show how to do this ... The value of the sentinel device is the value, if the user enters it again, must stop the program and print the two lowest numbers.
package hw4; public class s1 { public static void main(String[] args) { int input; int min; int min2; System.out.print("Enter a value to act as sentinel:"); int sentinel = IO.readInt(); System.out.println("Enter numbers"); input = IO.readInt(); do { min = input; min2 = input; if (input < min) { min = input; } input = IO.readInt(); } while (input != sentinel);
source share