forked from NischayKG/My_Java_Programs_of_Strings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinting_prime_characters.java
More file actions
35 lines (35 loc) · 884 Bytes
/
printing_prime_characters.java
File metadata and controls
35 lines (35 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//39.Program to Display the Characters in Prime Position a given String
import java.util.*;
class printing_prime_character
{
public static void main(String ard[])
{
Scanner sc=new Scanner(System.in);
char chr[]=sc.next().toCharArray();
int l=chr.length;
if(l>=2)
{
System.out.println(chr[1]);
}
int count=1,div=0;
if(l>=3)
{
for(int i=2;i<l;i++)
{
div=i+1;
for(int k=2;k<=div/2;k++)
{
if(div%k==0)
{
count=0;
}
}
if(count==1)
{
System.out.println(chr[i]);
}
count=1;
}
}
}
}