Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
import java.io.*; public class ICSE { void primeFactors()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(int n=1; n<=20; n++)//to make the program work for 20 numbers { System.out.println("Enter a number"); int num=Integer.parseInt(br.readLine()); for(int i=1; i<=num; i++) { if(num%i==0) // check if i is a factor { int count=0; //check if i is prime for(int j=1; j<=i; j++) { if(i%j==0) { count++; } }//for j if(count==2) { System.out.println(i); }//if count }//if n%i }//for i }//for n }//primeFactors() void palindromes()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(int n=1; n<=20; n++)//to make the program work for 20 words { System.out.println("Enter a string"); String str=br.readLine(); String reverse=""; for(int i=str.length()-1; i>=0; i--)//read the string backwards { char c=str.charAt(i); reverse=reverse+c; } if(str.equalsIgnoreCase(reverse)) { System.out.println(str+" is a palindrome"); } else { System.out.println(str+" is not a palindrome"); } }//for n }//vowels() public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ICSE obj=new ICSE(); int choice=0; do { System.out.println("1. Display prime factors for 20 numbers"); System.out.println("2. Check palindromes for 20 words"); System.out.println("3. Exit Program"); System.out.println("Enter choice"); choice=Integer.parseInt(br.readLine()); switch(choice) { case 1: obj.primeFactors(); break; case 2: obj.palindromes(); break; case 3: System.out.println("Quitting program"); break; default: System.out.println("Wrong choice"); }//switch }while(choice!=3); System.out.println("Thanks"); }//main }//class