-
Notifications
You must be signed in to change notification settings - Fork 97
/
P2captialcount.java
56 lines (50 loc) · 1.22 KB
/
P2captialcount.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package exp03;
import java.util.Scanner;
public class P2captialcount {
public static void main(String[] args) {
Scanner sc= new Scanner (System.in);
System.out.println("Enter your string: ");
String sen = sc.nextLine();
sen = sen.trim();
char cap[]= new char[sen.length()];
int capi=0;
char sap[]= new char[sen.length()];
int sapi=0;
int flag=0;
for(int i=0;i<sen.length() ;i++) {
if(sen.charAt(i)>=65 && sen.charAt(i)<=90 &&sen.charAt(i)!=32) {
for(int c=0; c<=capi;c++)
if(cap[c] == sen.charAt(i)) {
flag=1;
}
if(flag==0) {
cap[capi]=sen.charAt(i);
capi=capi+1;
}
if(flag==1)
flag=0;
}
if(sen.charAt(i)>=97 && sen.charAt(i)<=122 &&sen.charAt(i)!=32) {
for(int c=0; c<=sapi;c++)
if(sap[c] == sen.charAt(i)) {
flag=1;
}
if(flag==0) {
sap[sapi]=sen.charAt(i);
sapi=sapi+1;
}
if(flag==1)
flag=0;
}
}
System.out.print("There are "+(capi)+" capital letters : ");
for(int i=0;i<capi;i++)
System.out.print(cap[i]);
System.out.println();
System.out.print("There are "+(sapi)+" small letters : ");
for(int i=0;i<sapi;i++)
System.out.print(sap[i]);
System.out.println();
sc.close();
}
}