Professional Documents
Culture Documents
Java Basic Program Manual
Java Basic Program Manual
Source code:
public 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");
}
}
2. Write a java program to check the given number is prime/not.
Source code:
}
if(count==3)
{
System.out.println("prime");
}
else
{
System.out.println("not a prime");
}
}
}
3. Program to check whether the given number is Armstrong number.
Source code:
number=num;
while(number!= 0)
{
temp = number % 10;
total = total + temp*temp*temp;
number /= 10;
}
if(total == num)
System.out.println(num + " is an Armstrong number");
else
System.out.println(num + " is not an Armstrong number");
}
}
import java.util.Scanner;
public class JavaExample {
public static void main(String[] args) {
// creating a scanner
Scanner scan = new Scanner(System.in);
// close scanner
scan.close();
}
}