-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmar14.java
More file actions
20 lines (18 loc) · 732 Bytes
/
Copy pathmar14.java
File metadata and controls
20 lines (18 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.util.Scanner;
public class mar14 {
public static void main(String args[]) {
int count = 0;
Scanner keyboard=new Scanner(System.in);
System.out.println("Enter a sentence: ");
String str=keyboard.nextLine();
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '!' || str.charAt(i) == ',' || str.charAt(i) == ';' || str.charAt(i) == '.'
|| str.charAt(i) == '?' || str.charAt(i) == '-' || str.charAt(i) == '\'' ||
str.charAt(i) == '\"'|| str.charAt(i) == ':') {
count++;
}
keyboard.close();
}
System.out.println("The number of punctuations exists in the string is: " + count);
}
}