-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay38_prob1.java
46 lines (35 loc) · 1.33 KB
/
Day38_prob1.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
/*
Write a program to take a String input from the user having length greater than 3. Ask the user to give character input and find how many no. of times that character is present in the string. If length of the string entered by the user is <=3, then display message "Invalid".
Input Format
Program should take 2 inputs in following sequence: 1) String input 2) Character input
Constraints
If length of the string entered by the user is <=3, then display message "Invalid" and the second input (i.e. character input) should not be taken from user.
Output Format
Display how many no. of times a particular character (specified by user at run-time) is present in the string.
Sample Input 0
brilliant
l
Sample Output 0
2
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
if(s.length()<=3){
System.out.println("Invalid");
return;
}
int count=0;
char ch = sc.nextLine().charAt(0);
for(int i=0;i<s.length();i++){
if(s.charAt(i)==ch){
count++;
}
}
System.out.println(count);
}
}