Prime Number Program in Java

Problem Description Write a Java program to check if a given number is a Prime number. If the number is Prime, then display it is a prime number else display it is not a prime number. What is Prime Number in Java? A prime number is a natural number that is greater than 1 and … Read more

advertisement

Fibonacci Series Program in Java

What is Fibonacci Series in Java? Fibonacci series are the numbers in the sequence 0, 1, 1, 2, 3, 5, 8, 13, 21….. The series in the Fibonacci sequence is equal to the sum of the previous two terms. The Fibonacci sequence’s first two terms are 0 and 1 respectively. Mathematically, we can denote it … Read more

advertisement

Java Program to Find Sum of Natural Numbers using While Loop

This is a Java Program to Find Sum of Natural Numbers Using While Loop. Enter the number upto which you want to calculate the sum. Now we use while loops till the given number to get the desired output. Here is the source code of the Java Program to Find Sum of Natural Numbers Using … Read more

advertisement

Java Program to Print Diamond Pattern

Problem Description Write a Java Program to Print Diamond Pattern. Problem Solution Enter the number of rows as an input. Now we use for loops to print two equiateral triangles facing away from each other but with same base. Program/Source Code Here is the source code of the Java Program to Print Diamond Pattern. The … Read more

advertisement

Star Pattern Program in Java

This is the Java Program to Print * in Triangular Pattern. Problem Description Write a Java Program to Print * in Triangular Pattern, upto n lines. Problem Solution The idea is to use nested loops. Iterate the first loop from 1 to n. Print the required number of spaces using a nested loop and finally … Read more

advertisement

Java Program to Calculate Simple Interest

Problem Description Write a Simple Interest Program in Java using the SI formula. What is Simple Interest in Java? Simple Interest is the sum of money that must be paid as an additional percentage of the principal money to the lender by the person who borrowed it. Problem Solution Formula to Calculate Simple Interest: Simple … Read more

advertisement

For Loop Program in Java

What is for loop in Java? A for loop in Java is a control flow statement used to repeatedly execute a block of code a fixed number of times. It consists of an initialization expression, a test expression, an update expression, and a block of code to be executed. It is commonly used for iterating … Read more

advertisement

Java Program to Find Product of Two Numbers using Recursion

This is a Java Program to Find Product of 2 Numbers using Recursion. Enter two integer numbers as an input. After that we pass the two given numbers along with zero to the other function where get numbers one by one to multiply with the help of recursion. Hence we get the product of the … Read more

advertisement

Sum of Natural Numbers using Recursion in Java

This is a Java Program to Find Sum of N Numbers using Recursion. Enter the number of elements you want and then enter all the required elements as an input. Now we pass all the elements along with the length of array and a zero to new function where we find sum of all the … Read more

advertisement

Java Program to Find GCD of Two Numbers

GCD stands for Greatest Common Divisor. GCD of two numbers in Java is the largest positive integer that completely divides both the given numbers. Example: GCD(10,15) = 15, GCD(12,15) = 3. Problem Description Write a Java Program to Find the GCD of two numbers. Problem Solution 1. Take two numbers as input. 2. Start a … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.