-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.java
More file actions
30 lines (30 loc) · 810 Bytes
/
Counter.java
File metadata and controls
30 lines (30 loc) · 810 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
import java.util.*;
public class Counter
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter jewels and stones");
String jewels=in.nextLine();
String stones=in.nextLine();
int l1=jewels.length();
int l2=jewels.length();
if(l1>50 || l1<1 || l2>50 || l2<1 || jewels.chars().distinct().count()!=l1|| !(jewels.matches("^[a-zA-Z]+$"))|| !(stones.matches("^[a-zA-Z]+$")))
{
System.out.println("Invalid input");
return;
}
int c=0;
for(int i=0;i<l1;i++)
{
char ch=jewels.charAt(i);
for(int j=0;j<l2;j++)
{
char ch1=stones.charAt(j);
if(ch==ch1)
c++;
}
}
System.out.println("No. of stones that are jewels:"+c);
}
}