a)Write a function ‘rev’ which returns the reverse of the given integer. Function isPalin takes an integer as argument and checks whether it is palindrome or not using rev function. Using isPalin write a main function to accept n integers and display number of palindrome numbers found. b)write a program to find the possible permutations of the given word . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

a)Write a function ‘rev’ which returns the reverse of the given integer. Function isPalin takes an integer as argument and checks whether it is palindrome or not using rev function. Using isPalin write a main function to accept n integers and display number of palindrome numbers found. b)write a program to find the possible permutations of the given word .

14th Sep 2016, 8:26 PM
ASTHA SINGH
ASTHA SINGH - avatar
2 Answers
+ 2
http://code.sololearn.com/c4896s1fQ1zc import java.util.Scanner; public class Program { public static int rev(int n) { int res = 0; while (n != 0) { res = res*10 + n%10; n = n/10; } return res; } public static boolean isPalin(int n) { return (n == rev(n)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Please enter how many numbers you want to check: "); int n = sc.nextInt(); System.out.println(n); System.out.println("Please enter the " + n + " numbers (separated by space)"); int count = 0; for (int i = 0; i < n; i++) { if (isPalin(sc.nextInt())) { count++; } } System.out.println(count + " palindrome(s) found."); } }
14th Sep 2016, 9:34 PM
Zen
Zen - avatar
+ 2
Permutations: http://code.sololearn.com/ceAgOb5QdtbP import java.util.Scanner; public class Program { private static void printPerm_rec(String fixed, String toChooseFrom) { int n = toChooseFrom.length(); if (n == 0) { System.out.println(fixed); } else { for (int i = 0; i < n; i++) { printPerm_rec(fixed + toChooseFrom.charAt(i), toChooseFrom.substring(0, i) + toChooseFrom.substring(i+1, n)); } } } public static void printPerm(String s) { printPerm_rec("", s); } public static void main(String[] args) { System.out.println("Permutations"); Scanner sc = new Scanner(System.in); System.out.print("Please enter a word: "); String s = sc.nextLine(); System.out.println(s); printPerm(s); } }
14th Sep 2016, 9:58 PM
Zen
Zen - avatar