0% found this document useful (0 votes)
63 views1 page

Write A Program in Java To Find Out If A Number Is Prime in Java

The document provides examples of common programming exercises in Java, including writing programs to check if a number is prime, a power of 2, an Armstrong number, and to print the Fibonacci series up to a given number iteratively and recursively. Examples are given for each problem to help explain the concepts, such as the definition of a prime number and how Armstrong numbers are calculated using digit cubes. Both simple and multiple approaches are suggested for solving each problem.

Uploaded by

Angana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views1 page

Write A Program in Java To Find Out If A Number Is Prime in Java

The document provides examples of common programming exercises in Java, including writing programs to check if a number is prime, a power of 2, an Armstrong number, and to print the Fibonacci series up to a given number iteratively and recursively. Examples are given for each problem to help explain the concepts, such as the definition of a prime number and how Armstrong numbers are calculated using digit cubes. Both simple and multiple approaches are suggested for solving each problem.

Uploaded by

Angana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Write a program in Java to find out if a number is prime in Java?

A number is called prime if it is divisible by either itself or 1. There are many algorithms to find prime
numbers like, instead of dividing till number, division up to the square root of a number may be
enough. Start from the simplest one and then try to solve this problem in a couple of different ways.

How to find if a number is the power of 2 in Java?


This is another interesting Java programming exercise. This program can be solved using different
ways like using arithmetic operators or by using a bit shift operator.

Write Java program to check if a number is Armstrong's number or not?


An Armstrong number of 3 digits is a number for which sum of cube of its digits are equal to number
e.g., 371 is an Armstrong number because of 3*3*3 + 7*7*7 + 1*1*1 = 371).

Write a program in Java to print the Fibonacci series up to a given number? Write both
iterative and recursive versions.
Fibonacci series a popular number series and a very popular programming question in Java, in
which the number is equal to the sum of the previous two numbers, starting from third. Fibonacci
series is also a good recursion exercise and often asked in interviews as well.

You might also like