0% found this document useful (0 votes)
4 views

Java Practical

Uploaded by

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

Java Practical

Uploaded by

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

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)
System.out.println("palindrome number ");
else
System.out.println("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 java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner myObj = new Scanner(System.in);

int number = myObj.nextInt();


int originalNumber, remainder, result = 0;

originalNumber = number;

while (originalNumber != 0)
{
remainder = originalNumber % 10;
result += Math.pow(remainder, 3);
originalNumber /= 10;
}

if(result == number)
System.out.println("Armstrong");
else
System.out.println("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

You might also like