-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_1.java
More file actions
37 lines (23 loc) · 836 Bytes
/
Copy pathString_1.java
File metadata and controls
37 lines (23 loc) · 836 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
36
37
import java.util.Scanner;
public class String_1{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Write a String to count total no. of Characters in it. ");
String new_string = sc.next();
int count = 0 ;
int length = new_string.length();
System.out.println("the length of the string is " + length);
for(int i =0;i<length;i++)
{
if(new_string.charAt(i)!=' ')
{
count++;
}
}
// for(int i = 0; i < new_string.length(); i++) {
// if(new_string.charAt(i) != ' ')
// count++;
// }
System.out.println("Total No. of characters in the String:" + count);
}
}