Skip to main content

Posts

Showing posts with the label interview Questions

How to Remove Duplicates from ArrayList in Java | java Interview Questions

 How to Remove Duplicates from ArrayList in Java About Us : Introducing the RealNameHidden: Your Ultimate Guide to Java, Spring Boot, Hibernate, Databases, Problem Solving, and Interview Questions! Are you passionate about Java programming and eager to expand your knowledge in the world of software development? Look no further! Welcome to the realm of RealNameHidden, your go-to destination for all things related to Java, Spring Boot, Hibernate, Databases, Problem Solving, and Interview Questions. With a wealth of experience and expertise in the field, RealNameHidden is a dedicated YouTuber committed to sharing valuable insights, practical tips, and in-depth tutorials to help you master the intricacies of Java programming and its associated technologies. Whether you're a beginner taking your first steps into the programming world or an experienced developer seeking advanced concepts, this channel is designed to cater to all skill levels. RealNameHidden understands that Java programm

find the nearest prime number in java

 find the nearest prime number in java The closest prime can be greater or smaller than the passed input integer. If there are equi-distant  prime-numbers, print both. Example: Input#1: 32 Output#1: 31 Input#2: 30 Output#2: 29 31 Code:: import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); find(n); } public static void find(int num) { // greater number int num1 = num + 1; while (true) { if (isPrime(num1)) { break; } num1++; } // smaller int num2 = num - 1; while (num2 > 1) { if (isPrime(num2)) { break; } num2--; } // System.out.println(num1+" "+num2); if (num2 == 1) { System.out.println(num1); } else if (num1 - num == num - num2) { System.out.println(num2 + " " + num1); } else if (num1 - num < num - num2) { System.out.println(num1); } else { System.out.println(num2)

how to iterate hashmap in java

how to iterate hashmap in java  for explanation watch video:: 1) import java.util.*; public class Test{   public static void main(String args[])  {   HashMap<Integer,String> hm = new HashMap<>(); hm.put(1,"raja"); hm.put(2,"ram"); hm.put(3,"mohan"); hm.put(4,"roy"); for(Map.Entry<Integer,String> e : hm.entrySet()){ System.out.println(e.getKey() + " "+e.getValue()); } }    }  2) Code: import java.util.*; public class Test{   public static void main(String args[])  {   HashMap<Integer,String> hm = new HashMap<>(); hm.put(1,"raja"); hm.put(2,"ram"); hm.put(3,"mohan"); hm.put(4,"roy"); //keys for(int i : hm.keySet()){ System.out.print(i+" "); } System.out.println(); for(String s : hm.values()){ System.out.print(s+" "); } System.out.println(); }    }  3) import java.util.*