javatechie

Find Missing Element From Array

Sep 21st, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.33 KB | None | 0 0
  1. package com.javatechie.solution;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class FindMissingElementFromArray {
  6.  
  7.     public static void main(String[] args) {
  8.         int[] array={1,2,3,5};
  9.         int n=array.length+1;
  10.         int mid=n*(n+1)/2;
  11.         int sum= Arrays.stream(array).sum();
  12.         System.out.println(sum-mid);
  13.     }
  14. }
Add Comment
Please, Sign In to add comment