Common Java Examples Interview Questions - Part 3 || I love Programming

preview_player
Показать описание
In this video, I have discussed about different basic examples of Java programming which are being asked in Interviews.
It looks easy, but you have to practice to solve them quickly.

1 Java Program to Calculate the Power of a Number
2 Java Program to Check Whether a Number is Palindrome or Not
3 Java Program to Check Whether a Number is Prime or Not
4 Java Program to Display Prime Numbers Between Two Intervals
5 Java Program to Check Armstrong Number
6 Java Program to Display Factors of a Number
7 Java Program to Make a Simple Calculator Using switch...case

~~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

Paid courses (Recorded) videos:
Рекомендации по теме
Комментарии
Автор

Really I appreciate the way you trace the program, making mistakes then analyze the code, it click the logics, Yes I am learning and enjoying

arabindamohanty
Автор

Timestamps:
1. Java Program to Calculate the Power of a Number
1:09
2. Java Program to Check Whether a Number is Palindrome or Not
07:25
3. Java Program to Check Whether a Number is Prime or Not
13:24
4. Java Program to Display Prime Numbers Between Two Intervals
19:35

5. Java Program to Check Armstrong Number
23:40
6. Java Program to Display Factors of a Number
30:18
7. Java Program to Make a Simple Calculator Using switch...case 33:30

ParthKandpal
Автор

love your work; really enjoy all videos

CrystalisDota
Автор

Thank you Naveen. It is really helpful.

nageshphaniraj
Автор

Naveen, For prime number program there is another logic, declare a divisorCount variable and initialize it to 0 and run a for loop from 1 upto the number and get the divisorCount. If the divisorCount is 2, then it is a prime number or else it is a composite number.

sainagakumaraswamy
Автор

Another solution to "Is Palindrome or Not "


int isPalindromeOrNot=34343;
String
boolean isPalindrome=false;

for (int i = 1; i <= (s.length()/2); i++) {

if {
is not palindrome");


}else {

}
}

if (isPalindrome) {
is palindrome");
}

emrebaybas
Автор

@17.21 logic is wrong use num=25 its showing number is prime.

studymaster
Автор

package JavaQuestions;

import java.util.Scanner;

public class CalculatePowerOfNum {

public static void main(String[] args) {

int base = 5;
int exponent = 4;


int power = base;
int count = 1;

if(exponent!=0) {
for(int i = 1; i<exponent; i++) {

power = power*base; //16 4 9 27 81
count++; //2 2 3 2 3 4

}
System.out.println("power of number is "+ power);
}

else {

}

}

}

vijaya
Автор

Another way of prime number

for(int i=1;i<=number;i++){
if(i!=1&&i!=number){
if(number%i==0){
return false; } } }
if(number<=0){
return false;
}
else
return true;
}

mertm
Автор

Thanks Naveen Good task during the lockdown to learn and revise the Java Concepts.

khajazakiuddin
Автор

In both prime no.'s programs, it gives 4 is a prime number....please check once.

lishapatil
Автор

Used below logic for armstrong number

int num=153;

int actualnumber=153;
int pow=0;
while(num!=0)
{
int n=num%10;
pow =pow+n*n*n; //27+125
num=num/10;
}

if(actualnumber == pow)
{
System.out.println(pow + " is aramstrong number");
}else System.out.println(pow + " is not a aramstrong number");
}

sumitpatil
Автор

Hi Naveen, Your videos are helpfull.Please try to cover videos for Very complex java programs

rajateshr
Автор

ArmStrong Between Numbers:

public void armStrongBetweenNumbers(){
int low = 140;
int high = 440;
double result = 0;

while(low<=high){
int changednum=low;
while(changednum!=0) {
int n = changednum % 10;
result = result + Math.pow(n, 3);
changednum = changednum / 10;

if(result==low){
System.out.println(result);
break;
}
}

low++;
result =0;
}

}

happybeingsagar
Автор

First time I started loving Java coding but now there is no video after part 5. I am stuck again. :(

palr
Автор

You have hard coded the value and also have used math library, what if the length of number is 4? We should again hard code the value right?

karthikfs
Автор

Why do we need to write this statement "i<=num/2" in the prime no program?

amanchandrani
Автор

One more short way to check prime number -


Scanner scanner = new Scanner(System.in);

System.out.println("Enter a number: ");
int num = scanner.nextInt();

int i;

for(i=2; i<num && num%i!=0; i++ );
if(i==num) {
System.out.println("Number is prime: " +num);
}else {
System.out.println("Number is not prime: " +num);
}

CS_
Автор

Thank you a lot sir... Sir, I have messaged you on the telegram group please reply...

amanchandrani