1 Problem Statement
Write a Program whether number entered is palindrome or not.
Instructions
Input: MaM
Output: palindrome or Not palindrome
class PalindromeExample{
public static void main(String args[]){
int r,sum=0,temp;
int n=454;//It is the number variable to be checked for palindrome
temp=n;
while(n>0){
r=n%10; //getting remainder
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
[Link]("palindrome number ");
else
[Link]("not palindrome");
}
}
Console input : MaM
2 Problem Statement
Write a Program whether number entered is armstrong or not.
Instructions
To find entered number is Armstrong or not.
Input: 371
output: Not Armstrong and Armstrong
import [Link].*;
public class Main
{
public static void main(String[] args)
{
Scanner myObj = new Scanner([Link]);
int number = [Link]();
int originalNumber, remainder, result = 0;
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber % 10;
result += [Link](remainder, 3);
originalNumber /= 10;
}
if(result == number)
[Link]("Armstrong");
else
[Link]("Not Armstrong");
}
}
3 Problem Statement
Write a Program to print all even from 1 to N using for loop.
Instructions
To print the list of even numbers.
Input: 2
output: 24