D.Tech Academic
Deep Singh
Pages
Core Java
Web App
Spring
Hibernate
Kotlin
Android
Python
Flutter
Spring Boot
Find Missing number in Java Puzzle
Find missing number in java puzzle
public class JavaPuzzle { int sumOfTotalNnumbers(int num) { int sum = (num * (num+1))/ 2; return sum; } int sumOfAllElements(int[] items) { int sum = 0; for (int i = 0; i < items.length; i++) { sum = sum + items[i]; } return sum; } public static void main(String[] args) { JavaPuzzle jp=new JavaPuzzle(); int num = 10; int[] items = {1, 2, 5, 3, 7, 8, 6,9,4}; int son = jp.sumOfTotalNnumbers(num); int soi = jp.sumOfAllElements(items); System.out.println(son-soi + " is the missing number"); } }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment