Sum of Number
package Afterfeb4;
public class sumofnumber {
public static void main(String[] args) {
int no = 96785;
int sum = 0;
while (no > 0) {
sum = sum + no % 10;
no = no / 10;
}
System.out.println("sum of number = " + sum);
}
}
Output:sum of number = 35
ReverseNumber:
package Afterfeb4;
public class ReverseNumber {
public static void main(String[] args) {
int no = 12345;
int reverse = 0;
int count = 0;
while (no > 0) {
reverse = (reverse * 10) + no % 10;// 54321
no = no / 10;// 1234 123 12 1
count++;
}
System.out.println("reverse = " + reverse);
System.out.println("count = " + count);
}
}
Output:
reverse = 54321
count = 5
Palindrome reverse also same meaning ex;mam ex;414
package Afterfeb4;
public class Palindrome {
public static void main(String[] args) {
int no1 = 414;
int no2 = no1;// no2=414
int reverse = 0;
while (no1 > 0) {
reverse = (reverse * 10) + no1 % 10;
no1 = no1 / 10;
}
if (reverse == no2)// if we give no1 it will give not palindrome because no1 is decease to zero
System.out.println("palindrome");
else
System.out.println("NOT Palindrome");
}
}
Output:
palindrome
ArmstrongNumber
An Armstrong number is a positive m-digit number that is equal to the sum of the mth powers of their digits. It is also known as pluperfect, or Plus Perfect, or Narcissistic number. Letβs understand it through an example.
Armstrong Number Example
1: 11 = 1
2: 21 = 2
3: 31 = 3
153: 13 + 53 + 33 = 1 + 125+ 27 = 153
125: 13 + 23 + 53 = 1 + 8 + 125 = 134 (Not an Armstrong Number)
1634: 14 + 64 + 34 + 44 = 1 + 1296 + 81 + 256 = 1643
Reference:https://www.javatpoint.com/armstrong-number-in-java
package Afterfeb4;
public class AmstrongNumber {
public static void main(String[] args) {
int no1 = 153;
int no2 = no1;
int armstrong = 0;
while (no1 > 0) {
int a = no1 % 10;
armstrong = armstrong + (a * a * a);
no1 = no1 / 10;
}
System.out.println(armstrong);
if (armstrong == no2)
System.out.println("armstrong");
else
System.out.println("not armstrong");
}
}
Output:
153
armstrong
NeonNumber:
Neon Number
A positive integer whose sum of digits of its square is equal to the number itself is called a neon number.
Example of Neon Number
Let's take an example and check 9 and 45 are neon numbers or not.
Neon Number in Java
Steps to Find Neon Number
Read an integer from the user or initialize a number (n) to check.
Calculate the square of the given number (n) and store it in variable sq.
Find the sum of the digits of the square (sq) and store the sum in the variable (sum).
Compare the given number n with If both are equal, the given number is a neon number, else, not a neon number.
Referencehttps://www.javatpoint.com/neon-number-in-java
package Afterfeb4;
public class neonNumber {
public static void main(String[] args) {
int no1 = 9;
int no2 = no1 * no1;// 9*9=*81=1+8=9 //81--> into loop then 8
int neon = 0;
while (no2 > 0) {
neon = (neon) + no2 % 10;// 1 8
no2 = no2 / 10;// 81---->8
}
System.out.println("Number = "+neon);
if (no1 == neon)
System.out.println("NeonNumber");
else
System.out.println("NOt NeonNumber");
}
}
Output:
Number = 9
NeonNumber
emirpNumber:
A number is called an emirp number if we get another prime number on reversing the number itself. In other words, an emirp number is a number that is prime forwards or backward. It is also known as twisted prime numbers.
Note: Palindrome primes are excluded.
Emirp Number Example
Suppose, we want to check the number 79 is emirp or not.
We know that 79 is a prime number means that divisible by 1 and self only. On reversing the number, we get 97 which is another prime number. Therefore, 79 and 97 both are prime numbers. Hence, 79 is a prime number. Similarly, we can check other numbers also.
Some other emirp numbers are 13, 199, 107, 113, 1399, 1583, 1201, 3049, etc.
Steps to find Emirp Number
Read or initialize a number (n).
First, check the given number (n) is prime or not.
If not, break the execution and exit.
If prime, find the reverse (r) of the given number (n).
Check the reverse number (r) is prime or not.
If not, print number (n) is not emirp.
If prime, print the given number (n) as an emirp number.
Reference:https://www.javatpoint.com/emirp-number-in-java
package Afterfeb4;
public class emirpNumber {
public static void main(String[] args) {
int no =13;
int emirp = 0;//13 --> 31reverse of no aslo a prime number
while (no > 0) {
emirp = (emirp * 10) + no % 10;
no = no / 10;
}
System.out.println(emirp);
if (emirp % 2 != 0 && emirp%3!=0 )
System.out.println("emirpNumber");
else
System.out.println("NOt emirpNumber");
}
}
Output:
71
emirpNumber
Primenumber:
package Afterfeb4;
public class primeNumber {
public static void main(String[] args) {
int no =5;
if (no% 2 != 0 && no%3!=0 )
System.out.println("primeNumber");
else
System.out.println("NOt primeNumber");
}
}
output:primeNumber
Top comments (0)