PRIME_STRING PROGRAM THROUGH JAVA
import java.util.*;
class primeString
{
public static void main(String args[])
{ int p=0,s=0,h=0;
String x="",m="";
char iq='\u0000';
Scanner sc=new Scanner(System.in);
System.out.println("Enter Sentence");
String n=sc.nextLine();
String a[]=new String[1000];
int y[]=new int[1000];
char c1[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
n=n+" ";
for(int i=0;i<n.length();i++)
{
char ch=n.charAt(i);
if(ch!=' ')
{
x=x+ch;
}
else
{
a[p]=x;
p++;
x="";
}
}
for(int i=0;i<p;i++)
{
int l=a[i].length();
for(int j=0;j<l;j++)
{
for(int k=0;k<26;k++)
{
char ch=a[i].charAt(j);
if(ch==c1[k])
{
s=s+k+1;
}
}
}
y[h]=s;
h++;
s=0;
}
for(int t=0;t<h;t++)
{ int q=0;
for(int i=1;i<=y[t];i++)
{
if(y[t]%i==0)
q++;
}
if(q==2)
{
iq=a[t].charAt(0);
for(int j=a[t].length()-1;j>0;j--)
{
char ch1=a[t].charAt(j);
if(ch1!=' ')
{
m=m+ch1;
}
}
System.out.print(iq+m);
m="";
iq='\u0000';
}
else
{
for(int j=0;j<a[t].length();j++)
{
char ch1=a[t].charAt(j);
if(ch1=='a'||ch1=='e'||ch1=='i'||ch1=='o'||ch1=='u')
{
System.out.print("*");
}
else
System.out.print(ch1);
}
}
System.out.print(" ");
}
}
}
OUTPUT :
INPUT: Enter Sentence
this is an apple.
OUTPUT: th*s *s *n *ppl*.
--------------------END-----------------
import java.util.*;
class primeString
{
public static void main(String args[])
{ int p=0,s=0,h=0;
String x="",m="";
char iq='\u0000';
Scanner sc=new Scanner(System.in);
System.out.println("Enter Sentence");
String n=sc.nextLine();
String a[]=new String[1000];
int y[]=new int[1000];
char c1[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
n=n+" ";
for(int i=0;i<n.length();i++)
{
char ch=n.charAt(i);
if(ch!=' ')
{
x=x+ch;
}
else
{
a[p]=x;
p++;
x="";
}
}
for(int i=0;i<p;i++)
{
int l=a[i].length();
for(int j=0;j<l;j++)
{
for(int k=0;k<26;k++)
{
char ch=a[i].charAt(j);
if(ch==c1[k])
{
s=s+k+1;
}
}
}
y[h]=s;
h++;
s=0;
}
for(int t=0;t<h;t++)
{ int q=0;
for(int i=1;i<=y[t];i++)
{
if(y[t]%i==0)
q++;
}
if(q==2)
{
iq=a[t].charAt(0);
for(int j=a[t].length()-1;j>0;j--)
{
char ch1=a[t].charAt(j);
if(ch1!=' ')
{
m=m+ch1;
}
}
System.out.print(iq+m);
m="";
iq='\u0000';
}
else
{
for(int j=0;j<a[t].length();j++)
{
char ch1=a[t].charAt(j);
if(ch1=='a'||ch1=='e'||ch1=='i'||ch1=='o'||ch1=='u')
{
System.out.print("*");
}
else
System.out.print(ch1);
}
}
System.out.print(" ");
}
}
}
OUTPUT :
INPUT: Enter Sentence
this is an apple.
OUTPUT: th*s *s *n *ppl*.
--------------------END-----------------