SlideShare a Scribd company logo
HOW MANY TIMES NUMBEROCCUR
import java.util.*;
public class Main {
public static void main(String[]
args) {
int[] arr = {2, 3, 2, 4, 5, 3, 4, 4};
Map<Integer, Integer> map =
new HashMap<>();
for (int num : arr) map.put(num,
map.getOrDefault(num, 0) + 1);
map.forEach((k, v) ->
System.out.println(k + " occurs " + v
+ " times."));
}
}
HOW MANY TIMES DIGIT OCCUR
import java.util.*;
public class Main {
public static void main(String[]
args) {
String s = "Hello
World".toLowerCase().replaceAll("[
^a-z]", "");
Map<Character, Integer> m =
new HashMap<>();
for (char c : s.toCharArray())
m.put(c, m.getOrDefault(c, 0) + 1);
m.forEach((k, v) ->
System.out.println(k + " = " + v));
} }
import java.util.*; //zero to last
public class Main {
public static void main(String[]
args) {
int[] arr = {0, 1, 0, 3, 12};
int index = 0;
for (int num : arr) if (num != 0)
arr[index++] = num;
while (index < arr.length)
arr[index++] = 0;
System.out.println(Arrays.toString(
arr)); }}
ascending order and descding order
import java.util.*;
public class Main {
public static void main(String[] args) {
Integer[] a = {5, 2, 9, 1, 7};
Arrays.sort(a); // Ascending
System.out.println("Asc: " +
Arrays.toString(a));
Arrays.sort(a, Collections.reverseOrder())
// Descending
System.out.println("Desc: " +
Arrays.toString(a));
}
}
LINEAR SEARCH
public class LinearSearchShort {
public static void main(String[] args) {
int[] arr = {5, 8, 2, 9, 4};
int target = 9;
boolean found = false;
for (int i = 0; i < arr.length; i++) {
if (arr[i] == target) {
System.out.println("Found at index " + i);
found = true;
break;
}
}
if (!found)
System.out.println("Not found"); } }
BINARY SEARCH
public class BinarySearchSimple {
public static void main(String[] args) {
int[] arr = {1, 3, 5, 7, 9}; // already sorted
int target = 5;
int low = 0, high = arr.length - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (arr[mid] == target) {
System.out.println("Found at index " + mid);
return;
} else if (arr[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}
} System.out.println("Not found"); }}
palindrome number armstrong number fibonaccii

More Related Content

PPTX
Basic java, java collection Framework and Date Time API
PDF
ArrayOperations.java import java.util.Arrays; import java.util.pdf
PDF
import java.awt.LinearGradientPaint; public class searchComparis.pdf
DOCX
QA Auotmation Java programs,theory
DOCX
Spark_Documentation_Template1
PPTX
What is new in Java 8
DOCX
Dotnet 18
DOCX
Data Structures Using C Practical File
Basic java, java collection Framework and Date Time API
ArrayOperations.java import java.util.Arrays; import java.util.pdf
import java.awt.LinearGradientPaint; public class searchComparis.pdf
QA Auotmation Java programs,theory
Spark_Documentation_Template1
What is new in Java 8
Dotnet 18
Data Structures Using C Practical File

Similar to palindrome number armstrong number fibonaccii (20)

PDF
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
PDF
Useful javascript
PDF
Refer to my progress on this assignment belowIn this problem you w.pdf
PPTX
Java arrays
PPTX
Anti patterns
PDF
Google Guava for cleaner code
PDF
Java Assignment.Implement a binary search algorithm on an array..pdf
DOCX
Java Program
DOCX
Data structure and algorithm lab spiral (1) (4) (1).docx
DOCX
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
DOCX
cs3381-object oriented programming-ab-manual
DOCX
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
PDF
Beauty and the beast - Haskell on JVM
DOCX
Java programs
PDF
Java programs
PDF
Evolving with Java - How to Remain Effective
PDF
ISCP internal.pdf
PDF
GeoGebra JavaScript CheatSheet
PDF
Core java pract_sem iii
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Useful javascript
Refer to my progress on this assignment belowIn this problem you w.pdf
Java arrays
Anti patterns
Google Guava for cleaner code
Java Assignment.Implement a binary search algorithm on an array..pdf
Java Program
Data structure and algorithm lab spiral (1) (4) (1).docx
(JAVA NetBeans) Write a Java program able to perform selection sort-So.docx
cs3381-object oriented programming-ab-manual
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Beauty and the beast - Haskell on JVM
Java programs
Java programs
Evolving with Java - How to Remain Effective
ISCP internal.pdf
GeoGebra JavaScript CheatSheet
Core java pract_sem iii
Ad

Recently uploaded (20)

PPTX
web development for engineering and engineering
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Geodesy 1.pptx...............................................
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Sustainable Sites - Green Building Construction
PPT
Mechanical Engineering MATERIALS Selection
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Well-logging-methods_new................
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
web development for engineering and engineering
Embodied AI: Ushering in the Next Era of Intelligent Systems
Geodesy 1.pptx...............................................
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
R24 SURVEYING LAB MANUAL for civil enggi
CH1 Production IntroductoryConcepts.pptx
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
UNIT 4 Total Quality Management .pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Sustainable Sites - Green Building Construction
Mechanical Engineering MATERIALS Selection
Internet of Things (IOT) - A guide to understanding
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Well-logging-methods_new................
Fundamentals of safety and accident prevention -final (1).pptx
Foundation to blockchain - A guide to Blockchain Tech
Ad

palindrome number armstrong number fibonaccii

  • 1. HOW MANY TIMES NUMBEROCCUR import java.util.*; public class Main { public static void main(String[] args) { int[] arr = {2, 3, 2, 4, 5, 3, 4, 4}; Map<Integer, Integer> map = new HashMap<>(); for (int num : arr) map.put(num, map.getOrDefault(num, 0) + 1); map.forEach((k, v) -> System.out.println(k + " occurs " + v + " times.")); } }
  • 2. HOW MANY TIMES DIGIT OCCUR import java.util.*; public class Main { public static void main(String[] args) { String s = "Hello World".toLowerCase().replaceAll("[ ^a-z]", ""); Map<Character, Integer> m = new HashMap<>(); for (char c : s.toCharArray()) m.put(c, m.getOrDefault(c, 0) + 1); m.forEach((k, v) -> System.out.println(k + " = " + v)); } }
  • 3. import java.util.*; //zero to last public class Main { public static void main(String[] args) { int[] arr = {0, 1, 0, 3, 12}; int index = 0; for (int num : arr) if (num != 0) arr[index++] = num; while (index < arr.length) arr[index++] = 0; System.out.println(Arrays.toString( arr)); }}
  • 4. ascending order and descding order import java.util.*; public class Main { public static void main(String[] args) { Integer[] a = {5, 2, 9, 1, 7}; Arrays.sort(a); // Ascending System.out.println("Asc: " + Arrays.toString(a)); Arrays.sort(a, Collections.reverseOrder()) // Descending System.out.println("Desc: " + Arrays.toString(a)); } }
  • 5. LINEAR SEARCH public class LinearSearchShort { public static void main(String[] args) { int[] arr = {5, 8, 2, 9, 4}; int target = 9; boolean found = false; for (int i = 0; i < arr.length; i++) { if (arr[i] == target) { System.out.println("Found at index " + i); found = true; break; } } if (!found) System.out.println("Not found"); } }
  • 6. BINARY SEARCH public class BinarySearchSimple { public static void main(String[] args) { int[] arr = {1, 3, 5, 7, 9}; // already sorted int target = 5; int low = 0, high = arr.length - 1; while (low <= high) { int mid = (low + high) / 2; if (arr[mid] == target) { System.out.println("Found at index " + mid); return; } else if (arr[mid] < target) { low = mid + 1; } else { high = mid - 1; } } System.out.println("Not found"); }}