-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from shreeyachatzz/patch-6
Create PalindromeArray.java
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
Program's_Contributed_By_Contributors/Java_Programs/Misc/PalindromeArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//Coded by shreeyachatzz | ||
//Accept integer numbers from user and print only the palindrome numbers. | ||
import java.util.*;//importing | ||
public class palin//declaring class | ||
{ | ||
void checkpalin(int m)//to check if number is palindrome | ||
{ | ||
int s=0; | ||
for( int i= m; i>0 ; i=i/10)//finding the reverse of the number using for-loop | ||
{ | ||
int p= i%10; | ||
s = s*10+p; | ||
} | ||
if( s== m )//to check if rev is equal to the original | ||
{ | ||
System.out.print(m+" "); | ||
} | ||
} | ||
|
||
public static void main (String args[])//main method | ||
{ | ||
Scanner sc= new Scanner (System.in);//Scanner class | ||
int a[]= new int[500];//Declaring array | ||
System.out.println("Enter the no. of integers you want to input:"); | ||
int n= sc.nextInt();//accepting the number of integers to be checked | ||
System.out.println("Enter the Integers:");//use for-loop to accept integers from user | ||
for( int i= 0; i<n; i++) | ||
{ | ||
a[i]= sc.nextInt(); | ||
} | ||
palin ob= new palin();//calling function palin() | ||
//printing the palindrome numbers of all the numbers entered | ||
System.out.println("The palindrome numbers of the "+n+" numbers entered are as follows: "); | ||
for (int i=0; i<n; i++) | ||
{ | ||
ob.checkpalin(a[i]); | ||
} | ||
} | ||
} | ||
/* | ||
OUTPUT(1): | ||
Enter the no. of integers you want to input | ||
5 | ||
Enter the Integers | ||
121 | ||
223 | ||
116 | ||
242 | ||
678 | ||
The palindrome numbers of the 5 numbers entered are as follows: | ||
121 242 | ||
OUTPUT(2): | ||
Enter the no. of integers you want to input | ||
5 | ||
Enter the Integers | ||
22322 | ||
11711 | ||
222222 | ||
34567 | ||
112233 | ||
The palindrome numbers of the 5 numbers entered are as follows: | ||
22322 11711 222222 | ||
* | ||
*/ | ||
|