Question d’entretien chez Servosys Solutions

1. Direct interview scheduled for the google meet round. Core Java, Hibernate, Spring Boot and MySql interview questions Asked me to the the coding by shared screen on find the number is prime or not on Notepad. Asked to find record of the 2nd highest salary from the database.

Réponse à la question d'entretien

Utilisateur anonyme

21 oct. 2024

Code for checking prime number. import java.util.Scanner; public class PrimeCheck { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a number: "); int number = scanner.nextInt(); scanner.close(); if (isPrime(number)) { System.out.println(number + " is a prime number."); } else { System.out.println(number + " is not a prime number."); } } public static boolean isPrime(int num) { if (num <= 1) { return false; // 0 and 1 are not prime } for (int i = 2; i <= Math.sqrt(num); i++) { if (num % i == 0) { return false; // divisible by i means it's not prime } } return true; } }