Lecture Videos
  1  import java.util.ArrayList;
  2  import java.util.Scanner;
  3  
  4  public class DistinctNumbers {
  5    public static void main(String[] args) {
  6      ArrayList<Integer> list = new ArrayList<>();
  7      
  8      Scanner input = new Scanner(System.in);   
  9      System.out.println("Enter integers (input ends with 0): ");
 10      int value;
 11      
 12      do {
 13        value = input.nextInt(); // Read a value from the input
 14        
 15        if (!list.contains(value) && value != 0) 
 16          list.add(value); // Add the value if it is not in the list
 17      } while (value != 0);
 18  
 19      // Display the distinct numbers
 20      System.out.print("The distinct integers are: ");
 21      for (int i = 0; i < list.size(); i++) 
 22        System.out.print(list.get(i) + " ");
 23    }
 24  }