Escolar Documentos
Profissional Documentos
Cultura Documentos
Class: 12
Subject: Computer
Submitted by: Srilanka
Submitted to: Asil ismail
Question 1
import java.util.*;
class PrimePalin
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter lower limit");
int n=sc.nextInt();
Question 2
import java.util.*;
class DigiRange
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no.");
int n= sc.nextInt();
int k=n;int s;int r=n;
while(k!=0)
{ n=r;r=0;s=n%10;n=n/10;
while(n!=0)
{int b=n%10;
if(b<s){
r=r*10+s;s=b;}
else if(b>s)
r=r*10+b;
n=n/10;
}
System.out.print(s);
k=k/10;
}
}
}
Question 3
Question 4
import java.util.*;
class Matrix_Pract2
{public static void main()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter value of m");
int m= sc.nextInt();
if(m<20&&m>3)
{ int a[][]=new int[m][m];
System.out.println("Enter no. in marix");
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
a[i][j]=sc.nextInt();
int b[]=new int[((m-2)*(m-2))];int c=0;
for(int i=1;i<m-1;i++)
for(int j=1;j<m-1;j++)
{b[c]=a[i][j]; c++;}
int t=0;
for(int i=0;i<c;i++)
for(int j=0;j<(c-1-i);j++)
{ if(b[j]>b[j+1])
{ t=b[j];
b[j]=b[j+1];
b[j+1]=t; } }
System.out.println("ORIGINAL MATRIX : ");
for(int i=0;i<m;i++)
{for(int j=0;j<m;j++)
System.out.print(a[i][j]+" ");
System.out.println();}
for(int d=0, i=1;i<m-1;i++)
for(int j=1;j<m-1;j++)
{a[i][j]= b[d];d++;}
System.out.println("REARRANGED MATRIX :");
for(int i=0;i<m;i++)
{for(int j=0;j<m;j++)
System.out.print(a[i][j]+" ");
System.out.println();}
System.out.println("DIAGONAL ELEMENTS :");
for(int i=0;i<m;i++)
{for(int j=0;j<m;j++)
if((i==j)||((i+j)==m-1))
System.out.print(a[i][j]+" ");
else
System.out.print(" ");
System.out.println();}
int e=0;
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
if((i==j)||((i+j)==m-1))
e=e+a[i][j];
System.out.println("SUM OF DIAGONAL ELEMENTS = "+e); }
else
System.out.println("THE MATRIX SIZE IS OUT OF RANGE !!!"); } }
Question 5
import java.util.*;
class Surprise
{public static void main()
{
Scanner sc= new Scanner(System.in);
int A[][] =new int[4][4];
System.out.println("Enter 16 nos.");
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
A[i][j]=sc.nextInt();
System.out.println("Original array:");
for(int i=0;i<4;i++){
for(int j=0;j<4;j++)
System.out.print(A[i][j]+" ");
System.out.println();}
int t=0;
for(int i=0;i<4;i++)
{for(int j=0;j<4;j++)
for(int k=0;k<(3-j);k++)
{if(A[i][k]>A[i][k+1])
{t=A[i][k];
A[i][k]=A[i][k+1];
A[i][k+1]=t;
}}
}
System.out.println("the resultant array :" );
for(int i=0;i<4;i++)
{for(int j=0;j<4;j++)
System.out.print(A[i][j]+" ");
System.out.println();
}} }
Question 6
Algorithm1. Start
2. Input nos. In matrix
3. Display the original matrix
4. Print the elements beyond left diagonal
5. Stop
import java.util.*;
class Diagonal
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int A[][]=new int[4][4];
System.out.println("Please enter no. in array");
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
A[i][j]=sc.nextInt();
for(int i=0;i<4;i++)
{for(int j=0;j<4;j++)
System.out.print(A[i][j]);
System.out.println();}
for(int i=0;i<4;i++)
{
for(int j=1;j<=(4-i);j++)
System.out.print(" ");
for(int k=(4-i);k<4;k++)
System.out.print(A[i][k]);
System.out.println();
}
}
}
Question 7
9.Stop
import java.util.*;
class Arrange
{public static void main()
{Scanner sc=new Scanner(System.in);
System.out.println("enter m");
int m= sc.nextInt();
System.out.println("enter n");
int n=sc.nextInt();
if((m<20&&m>2)&&(n>2&&n<20))
{int a[][]=new int[m][n];
System.out.println("Enter nos. in matrix");
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a[i][j]=sc.nextInt();
System.out.println("entered matrix");
for(int i=0;i<m;i++)
{for(int j=0;j<n;j++)
System.out.print(a[i][j]);
System.out.println();}
int max=0;int min=a[0][0];
int p1=0,p2=0,p3=0,p4=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{if(a[i][j]>max)
{max=a[i][j];p1=i;p2=j;}
if(a[i][j]<min)
{min=a[i][j];p3=i;p4=j;}
}
System.out.println("max term= "+max+" row= "+p1+" column=
"+p2);
System.out.println("min term= "+min+" row= "+p3+" column=
"+p4);
int t=0,p=0,q=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{p=i;q=j;
for(int k=i;k<m;k++)
for(int l=j;l<n;l++)
{if(a[k][l]<a[p][q])
{p=k;q=l;}
}
t=a[i][j];
a[i][j]=a[p][q];
a[p][q]=t;
}
System.out.println("new matrix:");
for(int i=0;i<m;i++)
{for(int j=0;j<n;j++)
System.out.print(a[i][j]);
System.out.println();}
}
}
}
Question 8
Write a program to enter nos. in 4x4 matrix.
Display the orginal matrix. Replace the elements
of left diagonal and right diagonal with 0. Also
display the sum of first and fourth column.
Algorithm1. Start
2. Input nos. In 4x4 matrix
3. Replace the elements of right diagonal with 0
4. Replace the elements of left diagonal with 0
5. Calculate the sum of elements of first and fourth column
6. Display the original matrix
7. Display the rearranged matrix
8. Display the sum of elements
9. Stop
import java.util.*;
class LeftRight
{public static void main()
Question 9
class Mirror
{public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value of m");
int m=sc.nextInt();
if(m<20&&m>2)
{
int a[][]=new int[m][m];
System.out.println("enter the nos. in matrix");
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
a[i][j]=sc.nextInt();
System.out.println("the original matrix : ");
for(int i=0;i<m;i++)
{for(int j=0;j<m;j++)
System.out.print(a[i][j]);
System.out.println();
}
int n=m-1;int t=0;
for(int i=0;i<(m/2);i++)
{for(int j=0;j<m;j++)
{t=a[j][i];
a[j][i]=a[j][n];
a[j][n]=t;
} n--;}
System.out.println("Mirrored matrix :");
for(int i=0;i<m;i++)
{for(int j=0;j<m;j++)
System.out.print(a[i][j]);
System.out.println(); }
else{ System.out.println("Sorry!!! out of range ");}
} }
Question 10
import java.util.*;
import java.io.*;
class Vow
{public static void main()throws IOException
{Scanner sc=new Scanner(System.in);
System.out.println("enter alphabets ");
char a[][]=new char[4][4];
for(int i=0;i<4;i++) for(int j=0;j<4;j++)
{a[i][j]=(char)System.in.read();}
System.out.println("original array");
for(int i=0;i<4;i++) {for(int j=0;j<4;j++)
System.out.print(a[i][j]+" ");
System.out.println();}
char b[][]=new char[4][4]; int x=0,y=0;
for(int i=0;i<4;i++) {for(int j=0;j<4;j++)
if(a[i][j]=='A'||a[i][j]=='E'||a[i][j]=='I'||a[i][j]=='O'|| a[i][j]=='U')
{b[x][y]=a[i][j];
y++;a[i][j]=' ';if(y==4){y=0;x++;} }}
for(int i=0;i<4;i++) for(int j=0;j<4;j++)
if(a[i][j]!=' ')
{ b[x][y]=a[i][j];
y++;if(y==4){y=0;x++;} }
System.out.println("new array");
for(int i=0;i<4;i++) {for(int j=0;j<4;j++)
System.out.print(b[i][j]+" ");
System.out.println();} } }
Question 11
import java.io.*;
class numbernames
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int p;int d;int v;int b;int n;int c;
System.out.println("Enter any number between 1 to 1000");
int a= Integer.parseInt(in.readLine());
Stringm[]={"","one","two","three","four","five","six","seven","eight","nine
","ten","eleven","twelve"thirteen","fourteen","fifteen","sixteen","seventee
n","eighteen","nineteen","twenty",
"thirty","forty","fifty","sixty","seventy","eighty","ninety","hundred","thous
and"};
if(a>0&&a<=20)
{
System.out.println(m[a]);
}
if(a>20&&a<=100)
{
p=a%10;
d=a/10;
System.out.println(m[20+(d-2)]+" "+m[p]); }
if(a>100&&a<1000)
{ n=a%100;
b=n%10;
v=n/10;
c=a/100;
System.out.println(m[c]+" hundred "+m[20+(v-2)]+" "+m[b]);
} } }
Question 12
3. Loop executesfor(j=65;j<=90;j++)
{for(i=0;i<l;i++)
{ch=str.charAt(i);
if(ch==(char)j||ch==(char)(j+32))
System.out.print(ch); }}
4. Stop.
import java.io.*;
class alphaorder
{
Question 13
4. Stop.
import java.io.*;
class combine
{public static void main(String args[])throws IOException
{InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
int l;int i;String s;s="";
System.out.println("Enter first string");
String str=in.readLine();
System.out.println("Enter second string");
String st=in.readLine();
l=str.length();
for(i=0;i<l;i++)
{s=s+str.charAt(i)+st.charAt(i); }
System.out.println(s);
}}
Question 14
import java.util.*;
class Enco
{public static void main()
{Scanner sc= new Scanner(System.in);
System.out.println("Enter Sring ");
String s=sc.nextLine();
System.out.println("Enter encoding factor");
int n=sc.nextInt();
String st="";int k=65+32;
for(int j=0;j<s.length();j++)
{char ch=s.charAt(j);
if(((int)ch)<(91+32-n))
st=st+(char)(((int)ch)+n);
else if(((int)ch)>=(91+32-n))
st=st+(char)(k+((int)ch-(123-n))); }
System.out.println("ecoded string= "+st);
//abcdefghijklmnopqrstuvwxyz
} }
Question 15
import java.util.*;
class Frequency
{ String text;
int countan,countand,len;
public Frequency()
{ text="";
len=0;
countan=0;
countand=0; }
public void accept(String N)
{ text=N;
len=text.length();
}
public void checkfreqan()
{ int x=0;
for(int i=0;i<len;i++)
{ char ch=text.charAt(i);
if(ch==' '||ch=='.'||ch==',')
{String st=text.substring(x,i);
x=i+1;
if(st.equals("an"))
countan++;
} } }
public void checkfreqand()
{ int x=0;
for(int i=0;i<len;i++)
{ char ch=text.charAt(i);
if(ch==' '||ch=='.'||ch==',')
{String st=text.substring(x,i);
x=i+1;
if(st.equals("and"))
countand++;
} } }
public void display()
{ System.out.println("Original String = "+text);
System.out.println("Frequency of an = "+countan);
System.out.println("Frequency of and = "+countand); }
public static void main()
{ Scanner sc= new Scanner(System.in);
System.out.println("Enter Text......");
String str= sc.nextLine();
Frequency ob=new Frequency();
ob.accept(str);
ob.checkfreqan();
ob.checkfreqand();
ob.display();
} }
Question 16
import java.util.*;
class Substring
{ public static boolean isSubstring(String s,String t)
{ int m=s.length();
int n=t.length();
int i=0;
for(int j=0;j<n;j++)
{if(s.charAt(i)==t.charAt(j)) i++;
if(i==m) return true; }
return false;
}
public static void main()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter string sequence be searched for");
String str=sc.nextLine();
System.out.println("Enter String in which to search for");
String st=sc.nextLine();
if(isSubstring(str,st))
System.out.println(str+" is substring of "+st);
else
System.out.println(str+" is not a substring of "+st);
}}
Question 17
9.Stop
import java.util.*;
class Strings
{public static void main()
{Scanner sc=new Scanner(System.in);
System.out.println("Enter a string/line of text ");
String origstr=sc.nextLine();
String outstr=swapPairs(origstr);
System.out.println("New string after swapping characters:");
System.out.println(outstr); }
public static String swapPairs(String str)
{int len=str.length();
int last=0;
if(len%2==0)
last=len-1;
else
last=len-2;
StringBuffer sb=new StringBuffer(str);
char ch1,ch2;
for(int i=0;i<last;i+=2){
ch1=sb.charAt(i);
ch2=sb.charAt(i+1);
sb.setCharAt(i,ch2);
sb.setCharAt(i+1,ch1); }
return sb.toString();
}}
Question 18
import java.util.*;
class Pract
{public static void main()
{Scanner sc= new Scanner(System.in);
System.out.println("Enter a string");
String st=sc.nextLine();
int l=st.length();
int x=0; String A[]=new String[l];
int c=0;
for(int i=0;i<l;i++)
{char ch=st.charAt(i);
if(ch==' '||ch=='.'||ch==',')
{String s= st.substring(x,i); A[c]=s;
x=i+1; c++;} }
System.out.println("No. of words = "+c);
String t="";
for(int i=0;i<=c;i++)
for(int j=0;j<c-1;j++)
if(A[j].compareTo(A[j+1])>0){
t=A[j]; A[j]=A[j+1];
A[j+1]=t;}
System.out.println("New String:");
for(int i=0;i<c;i++)
System.out.print(A[i]+" ");
}}
Question 19
Write a program to enter to enter the month first day and print the whole
calendar?
import java.util.*;
class CalendarProgram
{
//Function to match the given month and return its maximum days
int findMaxDay(String mname, int y)
{
String months[] = {"","January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
int D[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if((y%400==0) || ((y%100!=0)&&(y%4==0)))
{
D[2]=29;
}
int max = 0;
for(int i=1; i<=12; i++)
{
if(mname.equalsIgnoreCase(months[i]))
{
max = D[i]; //Saving maximum day of given month
}
}
return max;
}
//Function to match the given weekday name and return its weekday no.
int findDayNo(String wname)
{
for(int i=0;i<6;i++)
{
for(int j=f; j<7; j++)
{
if(x<=max)
{
A[i][j] = x;
x++;
}
}
f = 0;
}
for(int j=0; j<z; j++) //Adjustment to bring last (6th) row elements to first row
{
A[0][j]=A[5][j];
}
System.out.println("\n\t----------------------------------------------------");
}
}
Question 20
Write a program to input a double dimension matrix and print the pyramid out of it.
import java.util.*;
class Diagonal
{
public static void main()
{
Scanner sc = new Scanner(System.in);
int A[][]=new int[5][5];
System.out.println("Please enter no. in array");
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
A[i][j]=sc.nextInt();
for(int i=0;i<5;i++)
{
for(int j=1;j<=(5-i);j++)
System.out.print(" ");
for(int k=(5-i);k<=4;k++)
System.out.print(A[i][k]+" ");
System.out.println(" ");
}
}
}
Question 21
Write a program to enter a matrix and print it. Then rearrange the matrix
in ascending order. Print the rearranged matrix and find the sum of
diagonal elements.
Answer
import java.util.*;
class Matrix_Pract2
{public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter value of m");
int m= sc.nextInt();
if(m<20&&m>3)
{
int a[][]=new int[m][m];
System.out.println("Enter no. in marix");
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
a[i][j]=sc.nextInt();
int b[]=new int[((m-2)*(m-2))];int c=0;
for(int i=1;i<m-1;i++)
for(int j=1;j<m-1;j++)
{b[c]=a[i][j]; c++;}
int t=0;
for(int i=0;i<c;i++)
for(int j=0;j<(c-1-i);j++)
{ if(b[j]>b[j+1])
{
t=b[j];
b[j]=b[j+1];
b[j+1]=t;
}
}
System.out.println("ORIGINAL MATRIX : ");
for(int i=0;i<m;i++)
{for(int j=0;j<m;j++)
System.out.print(a[i][j]+" ");
System.out.println();}
System.out.print(a[i][j]+" ");
else
System.out.print(" ");
System.out.println();}
int e=0;
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
if((i==j)||((i+j)==m-1))
e=e+a[i][j];
Question 22
Write a program to enter a binary number and convert it to decimal
number?
import java.util.*;
class Binary2deci
{
Question 23
Write a program to enter the number of working of an employee and find
his weekly pay.
Answer
import java.util.*;
class Payment
{
Question 24
Write a program to enter a number and find whether it is magic or not.
Answer
import java.util.*;
class Magic
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int s=n;int c=0;
while(s>9)
{ n=s;c=0;
while(n!=0)
{c=c+(n%10);System.out.println(c);
n=n/10;}
s=c;
}
if(s==1)
System.out.println("Magic no.");
else
System.out.println("Not a Magic no.");
}
}
Output
Question 25
Write a program to enter a number and find its digit range and print the
same.
Answer
import java.util.*;
class DigiRange
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the no.");
int n= sc.nextInt();
int k=n;int s;int r=n;
System.out.println("the digi range is ");
while(k!=0)
{ n=r;r=0;s=n%10;n=n/10;
while(n!=0)
{int b=n%10;
if(b<s){
r=r*10+s;s=b;}
else if(b>s)
r=r*10+b;
n=n/10;
}
System.out.print(s+" ");
k=k/10;
}
}
}
Output
Question 26
}
}
OUTPUT
QUESTION 27
Write a program to enter the lower and upper limit and find the
primepalin number between them and print the same.
Answer
import java.util.*;
class PrimePalin
{
public static void main()
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter lower limit");
int n=sc.nextInt();
System.out.println("Enter upper limit");
int m= sc.nextInt();
System.out.println("Prime-Palindrome Nos.");
while(n<=m)
{
int k=n;int d=0;
while(k!=0)
{d=d*10+(k%10); k=k/10;}
if(d==n)
{int c=0;
for(int i=1;i<=n;i++)
if(n%i==0)
c++;
if(c==2)
System.out.println(n+" ");
}
n++;
}
}
}
Output
Question 28
Write a program to enter a string and find the frequency of an and and in
the given string and print the same.
Answer
import java.util.*;
class FrequencyOfAlpha
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter string");
String s=sc.nextLine();
int a=0;
for(int i=65;i<91;i++)
{
a=0;
for(int j=0;j<s.length();j++)
{
char ch=s.charAt(j);
if(ch==(char)i||ch==(char)(i+32))
a++;
}
if(a!=0)
System.out.println("Frequency of "+(char)i+"or"+(char)(i+32)+" = "+a);
}
}
}
Output
Question 29
Write a program to enter a double dimension matrix and find the mirror
image of it. Display both the matrix.
Answer
import java.util.*;
class Mirror
System.out.println(" ");}
}
else{
System.out.println("Sorry!!! out of range ");}
}
}
Output
Question 30
Write a program to enter a matrix. Fill zero in diagonal elements then find
the sum of first and fourth column.
Answer
import java.util.*;
class LeftRight
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter nos. in matrix");
int A[][]=new int[4][4];
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
A[i][j]=sc.nextInt();
System.out.println("the original matrix :");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
System.out.print(A[i][j]+" ");
System.out.println(" ");}
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{if(i==j)
A[i][j]=0;
if((i+j)==3)
A[i][j]=0;
}
System.out.println("New matrix :");
for(int i=0;i<4;i++)
{for(int j=0;j<4;j++)
System.out.print(A[i][j]+" ");
System.out.println(" ");
}
int s1=0,s4=0;
for(int i=0;i<4;i++)
{s1=s1+A[i][0];
s4=s4+A[i][3];}
System.out.println("Sum of first column = "+s1);
System.out.println("Sum of fourth column = "+s4);
}
}
Output
Question 31
Write a program to enter a matrix and find the maximum and minimum
term accordingly find its corresponding row or column. And rearrange the
matrix in ascending order.
Answer
import java.util.*;
class Arrange
{public static void main()
{Scanner sc=new Scanner(System.in);
System.out.println("enter m");
int m= sc.nextInt();
System.out.println("enter n");
int n=sc.nextInt();
if((m<20&&m>2)&&(n>2&&n<20))
{int a[][]=new int[m][n];
System.out.println("Enter nos. in matrix");
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a[i][j]=sc.nextInt();
System.out.println("entered matrix");
for(int i=0;i<m;i++)
{for(int j=0;j<n;j++)
System.out.print(a[i][j]+" ");
System.out.println(" ");}
int max=0;int min=a[0][0];
int p1=0,p2=0,p3=0,p4=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{if(a[i][j]>max)
{max=a[i][j];p1=i;p2=j;}
if(a[i][j]<min)
{min=a[i][j];p3=i;p4=j;}
}
System.out.println("max term= "+max+" row= "+p1+" column= "+p2);
System.out.println("min term= "+min+" row= "+p3+" column= "+p4);
int t=0,p=0,q=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{p=i;q=j;
for(int k=i;k<m;k++)
for(int l=j;l<n;l++)
{if(a[k][l]<a[p][q])
{p=k;q=l;}
}
t=a[i][j];
a[i][j]=a[p][q];
a[p][q]=t;
}
System.out.println("new matrix:");
for(int i=0;i<m;i++)
{for(int j=0;j<n;j++)
System.out.print(a[i][j]+" ");
System.out.println(" ");}
}
}
}
Output
Question 32
Write a program enter a string the rearrange string In ascending order.
Answer
import java.util.*;
class Alphabeti
{public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter string");
String st=sc.nextLine();
String s=st.toLowerCase();
int l=s.length();
String str="";
for(int i=0;i<l;i++)
{char ch= s.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{}else str=str+ch;
}
s=Character.toUpperCase(str.charAt(0))+str.substring(1);
System.out.println("Original String = "+st);
System.out.println("New String = "+s);str="";
for(int i=65;i<91;i++)
for(int j=0;j<s.length();j++)
{char ch=s.charAt(j);
if((ch==(char)i)||(ch==(char)(i+32)))
str=str+ch;
}
System.out.println("Final String = "+str);
}
}
Output
Question 33
Write a program to enter a number and find whether it is composite
magic or not and between a limit.
Answer
import java.util.*;
class Comagic
{public static void main()
{Scanner sc=new Scanner(System.in);
System.out.println("Enter lower limit");
int m=sc.nextInt();
System.out.println("Enter upper limit");
int n=sc.nextInt();
for(int i=m;i<=n;i++)
{
if(chk(i))
System.out.print(i+" ");}
}
public static boolean chk(int n)
{
int c=0;boolean a=false,b=false;
for(int i=1;i<n;i++)
if(n%i==0)
c++;
if(c!=2)
a=true;
int k=n;int s=0;
while(k>9)
{s=k;int d=0;
while(s!=0)
{d=d+s%10;
s=s/10;
}
k=d;
}
if(k==1)
b=true;
if((a==true)&&(b==true))
return true;
else return false;
}
Output
Question 34
Write a pro